这是我的蚂蚁目标:
<target name="jar" depends="compile">
<mkdir dir="build/jar" />
<jar destfile="build/jar/mobileAppQueuing.jar" basedir="build/classes">
<fileset dir="library" includes="*.jar" />
<manifest>
<attribute name="Main-Class" value="Main" />
</manifest>
</jar>
</target>
这是我在详细模式下启动蚂蚁目标时所拥有的:
> ... [javac]
> /Users/jeromeansia/git/mobileAppQueuing/MobileAppQueuing/src/model/Share.java
>
> jar:
> [mkdir] Created dir: /Users/jeromeansia/git/mobileAppQueuing/MobileAppQueuing/build/jar
> [jar] Building jar: /Users/jeromeansia/git/mobileAppQueuing/MobileAppQueuing/build/jar/mobileAppQueuing.jar
> [jar] adding directory META-INF/
> [jar] adding entry META-INF/MANIFEST.MF
> [jar] adding directory controller/
> [jar] adding directory model/
> [jar] adding entry APIHandler.class
> [jar] adding entry Main.class
> [jar] adding entry controller/CtrlShare.class
> [jar] adding entry model/Share.class
> [jar] adding entry commons-codec-1.9.jar
> [jar] adding entry commons-logging-1.2.jar
> [jar] adding entry fluent-hc-4.5.jar
> [jar] adding entry gson-2.3.1.jar
> [jar] adding entry hamcrest-core-1.3.jar
> [jar] adding entry httpclient-4.5.jar
> [jar] adding entry httpclient-cache-4.5.jar
> [jar] adding entry httpclient-win-4.5.jar
> [jar] adding entry httpcore-4.4.1.jar
> [jar] adding entry httpmime-4.5.jar
> [jar] adding entry jetty-6.1.26.jar
> [jar] adding entry jetty-util-6.1.26.jar
> [jar] adding entry jna-4.1.0.jar
> [jar] adding entry jna-platform-4.1.0.jar
> [jar] adding entry junit-4.12.jar
> [jar] adding entry mockito-all-1.9.5.jar
> [jar] adding entry scribe-1.3.2.jar
> [jar] adding entry servlet-api-2.5-20081211.jar
> [jar] adding entry twitter4j-async-4.0.3.jar
> [jar] adding entry twitter4j-core-4.0.3.jar
> [jar] adding entry twitter4j-examples-4.0.3.jar
> [jar] adding entry twitter4j-media-support-4.0.3.jar
> [jar] adding entry twitter4j-stream-4.0.3.jar
> [jar] No Implementation-Title set.No Implementation-Version set.No Implementation-Vendor set.
> [jar] Location: /Users/jeromeansia/git/mobileAppQueuing/MobileAppQueuing/build.xml:23:
>
>
> BUILD SUCCESSFUL Total time: 1 second
但是当我启动jar时,我得到以下内容:
Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/jetty/Handler
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.mortbay.jetty.Handler
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
答案 0 :(得分:0)
这是可运行jar的解决方案:
> <target name="jar" depends="compile"> <mkdir dir="build/jar" />
> <jar destfile="build/jar/mobileAppQueuing.jar" filesetmanifest="mergewithoutmain">
> <manifest>
> <attribute name="Main-Class" value="Main" />
> <attribute name="Class-Path" value="." />
> </manifest>
> <fileset dir="bin" />
> <zipgroupfileset dir="library" includes="*.jar"/>
> </jar> </target>