我正在尝试运行你好世界。我收到错误“无法加载Main-Class清单属性”
我遇到了错误,它的属性名称=“MainClass”,当我用Main-Class替换它时它运行正常。
属性名称是用户定义的,对吧?那我为什么会收到这个错误?
这是我的代码: -
<target name="run" depends="clean,build,jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true" />
</target>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="build">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" />
</target>
<target name="jar">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" >
<manifest>
<attribute name="MainClass" value="${main-class}" />
</manifest>
</jar>
</target>
</project>
这是错误部分的输出: -
sushil@sushil:~/java/hello_world$ ant
Buildfile: /home/sushil/java/hello_world/build.xml
clean:
[delete] Deleting directory /home/sushil/java/hello_world/build
build:
[mkdir] Created dir: /home/sushil/java/hello_world/build/classes
[javac] /home/sushil/java/hello_world/build.xml:39: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file to /home/sushil/java/hello_world/build/classes
jar:
[mkdir] Created dir: /home/sushil/java/hello_world/build/jar
[jar] Building jar: /home/sushil/java/hello_world/build/jar/hello_world.jar
run:
[java] Failed to load Main-Class manifest attribute from
[java] /home/sushil/java/hello_world/build/jar/hello_world.jar
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 1 second
感谢。