Task: You need to make an executable JAR file with a JavaFX game using the graphics engine from CodeGym.
For this you will need to :
- Fork from the repository https://github.com/CodeGymCC/project-maven.git
- Download your version of the project to your computer. Next, we will work with the pom.xml file, located in the root project folder.
- Add dependencies:
- com.codegym: desktop-game-engine:1.0 (this dependency will be covered in the next section)
- org.junit.jupiter: junit-jupiter-engine: 5.8.2 (with 'test' scope)
- leave the maven-compiler-plugin unchanged
- install the com.codegym: desktop-game-engine:1.0 dependency from the lib library to the local repository (google for help)
- add the maven-surefire-plugin, and make a configuration so that the StrangeTest test class does not run on build. The rest of the tests should run.
- add the maven-jar-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:
- all our JAR dependencies should be registered in
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoaderclass must be used, which can use the classpath from JAR files, and can also start a JavaFX application
Rsrc-Main-Class, the starting class of the game (com.codegym.games.racer.RacerGame) must be used
- add a plugin that will collect all dependencies (with 'compile' scope) and add them to some directory during the build
- 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.
- The phase for some of the plugins needs to be overridden.
- The project uses JDK version 18.0.1. This JDK version, or higher, must be installed 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:
<way to java 18> -jar <the name of the resultant jar file> //Example "C:\Users\leo12\.jdks\openjdk-188.8.131.52\bin\java.exe" -jar "E:\temp\project-maven-1.0.jar"
- As a result you will see:
- 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 Java 18+, and therefore will not run on Mac and Linux.
Project analysis. Watch after completion!