Maven - Can't Execute JAR

前端 未结 2 657
我在风中等你
我在风中等你 2020-12-13 01:22

After building a sample mvn project, I added my org.restlet dependencies & Java code.

Then, I successfully built my JAR via mvn install

相关标签:
2条回答
  • 2020-12-13 01:24

    If you dont have a manifest in your jar invoking java -jar will not work.

    Use this command if you dont have a manifest:

    java -cp foo.jar full.package.name.ClassName
    
    0 讨论(0)
  • 2020-12-13 01:46

    You need to set the main class in the manifest using the maven-jar-plugin

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.someclass.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    

    Taken from here.

    EDIT

    If you want to package the resulting jar with dependencies you can use this

    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.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>
    

    Taken from here.

    0 讨论(0)
提交回复
热议问题