1

I have java project. When I export it to file.jar, it can't be opened with double click.

When I test with the command line:

java -jar file.jar

It shows the message:

No main manifest attribute

but with:

java -cp app.jar com.somepackage.SomeClass

it runs perfectly.

I use IntelliJ IDEA and maven. Manifest code:

Manifest-Version: 1.0
Main-Class: StructureClasses.Main
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Answer is here: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven – Bor Laze May 07 '17 at 22:02
  • Possible duplicate of [How can I create an executable JAR with dependencies using Maven?](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) – Ice May 07 '17 at 22:02
  • See http://stackoverflow.com/a/42200519/104891 for the sample project. – CrazyCoder May 07 '17 at 22:10

2 Answers2

1

if you are importing any pictures or using any other files that are not file.jar create a folder and put all of the other files in use in file.jar in that folder with file.jar.

0

If you are already using Maven, take a look at the maven-assembly-plugin. I think it already does what you want with is mainClass property.

This is an example from the official page

  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
      [...]
      <archive>
        <manifest>
          <mainClass>org.sample.App</mainClass>
        </manifest>
      </archive>
    </configuration>
    [...]
  </plugin>

With this configuration, you should now be able to run the jar file either with double-click or java -jar. Remember that the mainClass property must be the fully qualified name of the class.

Santiago Alzate
  • 397
  • 3
  • 14