Problem running a Jar file

前端 未结 2 1763
陌清茗
陌清茗 2021-01-23 05:22

I\'ve compiled a java project into a Jar file, and am having issues running it.

When I run:

java -jar myJar.jar

I get the following err

相关标签:
2条回答
  • 2021-01-23 06:07

    You should specify your main class during jar creation with full path, something like:

    <target name="jar" depends="compile">
         <delete file="myJar.jar"/>
         <delete file="MANIFEST.MF"/>
         <manifest file="MANIFEST.MF">
            <attribute name="Main-Class" value="my.package.myClass"/>
        </manifest>
    
        <jar destfile="myJar.jar"
               basedir="."
               includes="**/*.class"
               manifest="MANIFEST.MF" />
    </target>
    
    0 讨论(0)
  • 2021-01-23 06:12

    In your manifest file, make sure you have the attribute Main-Class set to the name of the class containing your main() method. For example, if the package-qualified name of the class is my.cool.Class, then, in your JAR manifest, Main-Class should be set to my.cool.Class.

    Also made sure that you have a package declaration in your .java files (for example, in Class.java, make sure you have the proper package my.cool; declaration). Also, make sure your directory hierarchy is set up correctly (my.cool.Class should be in $SRC/my/cool/Class.java).

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