我正在使用Netty和ant制作应用程序。当我编译它时,没有错误。但是当我尝试运行jar文件时,会收到以下消息:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/netty/channel/ChannelFactory
Caused by: java.lang.ClassNotFoundException: org.jboss.netty.channel.ChannelFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.darkquest.gs.Server. Program will exit.
这是我的build.xml项目:
<project default="compile" basedir=".">
<property name="src" location="src" />
<property name="build" location="build" />
<property name="doc" location="doc" />
<property name="lib" location="lib" />
<property name="jar" location="runescape.jar" />
<target name="compile">
<delete file="${jar}" />
<delete dir="${build}" />
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}" debug="on">
<compilerarg value="-Xlint:unchecked"/>
<classpath>
<pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/netty.jar" />
<pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/slf4j.jar"/>
<pathelement location="${lib}/xstream.jar"/>
<pathelement location="${lib}/mysql-connector.jar" />
<pathelement location="${lib}/hex-string.jar" />
<pathelement path="${java.class.path}/"/>
</classpath>
</javac>
<jar basedir="${build}" destfile="${jar}" >
<manifest>
<attribute name="Main-Class" value="org.darkquest.gs.Server" />
</manifest>
</jar>
</target>
<target name="doc" depends="compile">
<javadoc sourcepath="${src}" destdir="${doc}" verbose="on" />
</target>
<target name="runls">
<java classname="org.darkquest.ls.Server" fork="true">
<jvmarg value="-Xms128m" />
<jvmarg value="-Xmx512m" />
<arg value="ls.conf" />
<classpath>
<pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/netty.jar" />
<pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/slf4j.jar"/>
<pathelement location="${lib}/xstream.jar"/>
<pathelement location="${lib}/mysql-connector.jar" />
<pathelement location="${lib}/hex-string.jar" />
<pathelement path="${jar}/" />
</classpath>
</java>
</target>
<target name="runserver">
<java classname="org.darkquest.gs.Server" fork="true">
<jvmarg value="-Xms128m" />
<jvmarg value="-Xmx512m" />
<arg value="server.conf" />
<arg value="f2p" />
<arg value="no" />
<classpath>
<pathelement location="${lib}/mina.jar" />
<pathelement location="${lib}/xpp3.jar" />
<pathelement location="${lib}/netty.jar" />
<pathelement location="${lib}/slf4j.jar"/>
<pathelement location="${lib}/xstream.jar"/>
<pathelement location="${lib}/mysql-connector.jar" />
<pathelement location="${lib}/hex-string.jar" />
<pathelement path="${jar}/" />
</classpath>
</java>
</target>
</project>
这些是netty库的罐子:
ls -la /usr/share/java/netty*
-rw-r--r-- 1 root root 1118026 2012-06-24 15:29 /usr/share/java/netty-3.5.1.Final.jar
lrwxrwxrwx 1 root root 37 2012-07-02 01:31 /usr/share/java/netty.jar -> /usr/share/java/netty-3.5.1.Final.jar
ls -la lib/
total 4904
drwxrwxrwx 1 user user 4096 2012-07-02 01:49 .
drwxr-xr-x 1 user user 4096 2012-07-02 02:21 ..
-rw-rw-rw- 1 user user 281694 2012-06-18 05:43 bsh.jar
-rw-r--r-- 1 user user 6148 2012-06-18 05:48 .DS_Store
-rw-rw-rw- 1 user user 1685 2012-06-18 05:43 hex-string.jar
-rw-rw-rw- 1 user user 2082557 2012-06-18 05:43 jmf.jar
-rw-rw-rw- 1 user user 112249 2012-06-18 05:43 junit.jar
-rw-r----- 1 user user 315582 2012-07-01 15:21 mina-core-1.1.7.jar
-rw-rw-rw- 1 user user 315582 2012-06-18 05:43 mina.jar
-rw-rw-rw- 1 user user 456729 2012-06-18 05:43 mysql-connector.jar
-rw-rw-rw- 1 user user 1118026 2012-07-02 01:49 netty.jar
-rw-rw-rw- 1 user user 13873 2012-06-18 05:43 slf4j.jar
-rw-rw-rw- 1 user user 24538 2012-06-18 05:43 xpp3.jar
-rw-rw-rw- 1 user user 261710 2012-06-18 05:43 xstream.jar
任何人都可以帮助我?
感谢。
答案 0 :(得分:6)
该错误表示在您的jar文件中找不到netty类org.jboss.netty.channel.ChannelFactory
。
尝试使用zipfileset
任务在jar中包含netty类:
<jar basedir="${build}" destfile="${jar}" >
<manifest>
<attribute name="Main-Class" value="org.darkquest.gs.Server" />
</manifest>
<zipfileset includes="**/*.class" src="${lib}/netty.jar" />
</jar>