- Fork from the repository https://github.com/vasylmalik/project-maven.git
- Download your version of the project to your computer. Next, we will work with the pom.xml file .
- Add dependencies:
- org.apache.commons: commons-lang3: 3.12.0
- org.openjfx: javafx-controls: 18.0.1
- com.javarush: desktop-game-engine:1.0 (this dependency will be covered in a separate post)
- org.junit.jupiter: junit-jupiter-engine: 5.8.2 (с scope test)
- Add plugins for:
- installing the com.javarush: desktop-game-engine:1.0 dependency from the lib library to the local repository (google for help);
- leave the maven-compiler-plugin plugin unchanged ;
- a plugin that will collect all dependencies (with scope compile) and add them to some directory during the build;
- the maven-jar-plugin plugin , which will make a jar file containing the game code and dependencies. In this plugin, you need to configure the MANIFEST.MF file to contain sections:
Class-Path
,Main-Class
andRsrc-Main-Class
- All
Class-Path
our JAR dependencies should be registered in. - A
Main-Class
class must be writtenorg.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
in that can use the classpath from JAR files, and can also start a JavaFX application. - The
Rsrc-Main-Class
starting class of the game (com.javarush.games.racer.RacerGame) must be registered in it.
- In the maven-surefire-plugin , make a configuration so that the StrangeTest test does not run on build. The rest of the tests should run.
- Add a “resources” section to say that the built JAR dependencies are a resource, so that the maven-jar-plugin puts them inside the JAR file in the lib/ folder
- Upload changes to your GitHub repository, send a link to it to the teacher.
Useful:
-
The build must be run with the mvn clean install command .
-
Running the game (via Maven) for the purpose of viewing can be done with the mvn javafx:run command.
-
Some plugins need to override phase .
-
The project uses JDK version 18.0.1. It must be downloaded on your computer.
-
When building through Maven, there will be errors at first. Read them carefully and you will simplify your life.
-
Do not change anything in the org.eclipse.jdt.internal.jarinjarloader package . It has a custom loader class (honestly copied from StackOverflow), in which the launch of the main method is changed to launch the JavaFX application. Use for educational purposes only.
-
If you complete all the points, as a result of the assembly you will receive a fat-JAR file . You can start and check that everything is done correctly with the command:
<path for java 18> -jar <name resulting jar file> //example "C:\Users\leo12\.jdks\openjdk-18.0.1.1\bin\java.exe" -jar "E:\temp\project-maven-1.0.jar"
-
The build depends on your operating system. That is, if a JAR file is built on Windows, it can be run on any Windows computer with Java18. And it can't be done on Mac and Linux.
How to run 1.Installing jar file as dependency in local .m2
//example
mvn install:install-file -Dfile=C:\Users\Administrator\IdeaProjects\project-maven/lib/desktop-game-engine.jar -DgroupId="com.javarush" -DartifactId=desktop-game-engine -Dversion="1.0" -Dpackaging=jar
2.Build
//example
mvn clean install
-
jar file launch:
//example java -jar "C:\Users\Administrator.m2\repository\jru\module3\project-maven\1.0\project-maven-1.0.jar"