【发布时间】:2018-12-10 06:21:24
【问题描述】:
我的构建使用下面的build.xml 文件完美编译和运行。
唯一的问题是我创建了一个 jar,但它在没有给出 Could not find or load main class 错误的情况下无法运行。
我已经阅读了几个关于常见 Could not find or load main class 错误的 Stack Overflow 答案。但是,我无法在下面的build.xml 中发现我做错了什么。
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default="run" name="My Project ">
<target name="run" depends="createjar">
<java classname="com.company.program.project.MyMainClass">
<classpath path="staging">
<fileset dir="C:\COMPANY\Eclipse\3.6-64\plugins">
<include name="org.eclipse.swt.*.jar" />
</fileset>
</classpath>
</java>
</target>
<target name="createjar" depends="compile">
<jar destfile="./builds/jars/swtgui.jar" basedir="./staging/com/company/program/project" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="com.company.program.project.MyMainClass" />
</manifest>
<!--
<fileset dir="./bin/com/company/program/project" includes="./*.class" />
-->
<fileset dir="C:\COMPANY\Eclipse\3.6-64\plugins\" includes="org.eclipse.swt.win32.win32.x86_64_3.6.0.v3650b.jar" />
</jar>
</target>
<target name="compile">
<javac includeantruntime="false" srcdir="./src" destdir="staging">
<classpath>
<fileset dir="C:\COMPANY\Eclipse\3.6-64\plugins">
<include name="org.eclipse.swt.*.jar" />
</fileset>
</classpath>
</javac>
</target>
<record name="./MyMainClass.log" loglevel="verbose" action="start"/>
MyProject.log
createjar:
[jar] found a total of 0 manifests in 2 resource collections
[jar] A$1.class added as A$1.class is outdated.
[jar] A$10.class added as A$10.class is outdated.
[jar] A$11.class added as A$11.class is outdated.
[jar] ...
[jar] No sources found.
[jar] Building jar: C:\my_workspace\my_project\builds\jars\swtgui.jar
[jar] adding directory META-INF/
[jar] adding entry META-INF/MANIFEST.MF
[jar] adding entry A$1.class
[jar] adding entry A$10.class
[jar] adding entry A$11.class
[jar] adding entry org.eclipse.swt.win32.win32.x86_64_3.6.0.v3650b.jar
[jar] No Implementation-Title set.No Implementation-Version set.No Implementation-Vendor set.
Location: C:\my_workspace\my_project\build.xml:16:
createjar: duration 0 seconds
正确指定了主类。正确指定了类路径 (basedir)。它在编译完成之前等待执行。等等。
我在下面留下了我的日志文件,但似乎ant 没有提供任何关于它为什么找不到我的主类的线索。有没有人立即发现上述两个文件有什么问题?
【问题讨论】:
-
我相信你的 jar 文件有类似 src/com/xxx 的结构 ....内部结构应该是 com/asd/... ..尝试更改 basedir="./staging/com/ company/program/project" 到 basedir="./staging/com/company/program/project/"