I know there have been many posts on this but I can't seem to find an appropriate solution. So I have my 3 classes, one with a main and from IntelliJ everything runs fine. But I cannot seem to run the .jar file that I have created.
I also have a manifest file that contains the following:
Manifest-Version: 1.0
Main-Class: beanParser
I created the jar through the build option in IntelliJ. Any suggestions?
Thanks
In a Java project, every executable jar file contains a main method. Usually, it is placed at starting point of the application. To execute a main method by a self-executing jar file, we must have a proper manifest file and wrap it with our project at the proper location.
MF file is located under main/java directory. In such cases Maven doesn't copy it to the output and won't pack into the JAR file, but IDEA incorrectly shows it as actual manifest in the Artifact Editor. In order to solve the problem you just need to move MANIFEST. MF file to main/resources/META-INF directory.
"Main-Class" attribute in MANIFEST. MF file specifies the program entry point or name of Main class, a class that contains the main method in Java. The main method is required to run Java program.
MANIFEST.MF should be in:
src/main/resources/META_INF/
NOT in:
src/main/java/META_INF/
Have you considered the following link?
For Maven have a look at the following clip or this one.
Here's a snipped I used in my project:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>your.main.Clazz</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With