java.lang.NoClassDefFoundError: org/jboss/netty/channel/ChannelFactory

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11286706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:31:52  来源:igfitidea点击:

java.lang.NoClassDefFoundError: org/jboss/netty/channel/ChannelFactory

javaantnettybuild.xmlchannelfactory

提问by user1193085

I'm making an app with Netty and ant. When I compile it, there is no error. But when I try to run the jar file, it gets these message:

我正在用 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.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.

This is my build.xml my project:

这是我的 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>

And these are the jars of the netty library:

这些是 netty 库的 jars:

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

Anyone can help me?

任何人都可以帮助我吗?

Thanks.

谢谢。

回答by Christopher Peisert

The error indicates that the netty class org.jboss.netty.channel.ChannelFactorycannot be found in your jar file.

该错误表明org.jboss.netty.channel.ChannelFactory在您的 jar 文件中找不到netty 类。

Try including the netty classes in your jar using the zipfilesettask:

尝试使用以下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>