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

user1193085 picture user1193085 · Jul 2, 2012 · Viewed 11.2k times · Source

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:

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.

This is my build.xml my project:

<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:

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.

Answer

Christopher Peisert picture Christopher Peisert · Jul 2, 2012

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

Try including the netty classes in your jar using the zipfileset task:

<jar basedir="${build}" destfile="${jar}" >
  <manifest>
    <attribute name="Main-Class" value="org.darkquest.gs.Server" />
  </manifest>
  <zipfileset includes="**/*.class" src="${lib}/netty.jar" />
</jar>