Reputation: 973
I am new to IntelliJ and Maven and have, as seems customary by now, encountered a problem. I have made a Maven project within IntelliJ which runs well from within IntelliJ. When I do a clean install however the jar that ends up in the target folder does not run. I get the following error: "Error: Could not find or load main class test2.jar" when trying to run it from the terminal. I expect this has something to do with the MANIFEST file (which I can't seem to find in my project structure) but I really do not know. Is this a common problem or have I been especially careless? Does anyone know of a way to straighten this out?
I do not believe my source code will be especially helpful to you here but I might be wrong. So if you want it I can post it in an edit.
Thanks for any help!
Upvotes: 1
Views: 2539
Reputation: 1575
You could create an executable jar
which contains all of its dependencies. It sets the class which contains the main()
method in the manifest and allows you to run your application:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.mainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The fat jar with all of its dependencies (except jre ofcourse) will be built to your target folder. You can run it with:
java -jar your-application-1.0-jar-with-dependencies.jar
To change the output of the jar name or any other tweaks, check out the assembly plugin documentation.
Upvotes: 2
Reputation: 512
You have to create an artifact first. Follow these steps
Click the + button and choose JavaFX application [from module 'YourModule']
[]1
If you're using any external libraries, you need to include in the artifact like this
Click on the Java FX tab on the right side, then click the 3 dot button to choose the Application class [The class that extends Application]
[]4
Click okay, and go to Build --> Build artifacts, and build the project.
Upvotes: 1