Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a class called Game in the package net.aGameName and am trying to export a runnable Jar using eclipse. In the project I have two external Jar files added, lwjgl.jar and lwjgl_util.jar.

When I go to File->Export->Runnable Jar File and choose the Launch configuration I use for testing (which works successfully) I am able to export the Jar file without any errors. Finally I open cmd and use java aGameName.jar and receive the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: aGameName/jar
Caused by: java.lang.ClassNotFoundException: aGameName.jar
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: aGameName.jar.  Program will exit.

When I open the manifest file it says:

Manifest-Version: 1.0
Class-Path: .
Main-Class: net.aGameName.Game

Can anyone easily spot the error that would be causing this? Thanks

share|improve this question
    
As you add more dependencies, you may find Eclipse's export functions don't cut the mustard; eventually you might want to look into Ant or Maven. –  Tom G Oct 25 '11 at 14:59

3 Answers 3

Try java -jar aGameName.jar.

java aGameName.jar will try to run a class file named aGameName/jar.class.

share|improve this answer
    
Unfortunately that still results in a similar error message except the main class that it is looking for is now net.aGameName.Game –  tgrosinger Oct 25 '11 at 14:59
    
What are you using for your Library Handling during export? –  skyuzo Oct 25 '11 at 19:35

To run the jar you have to specify java -jar JARFILENAME as @skyuzo indicated.

Below is an ant xml file that should generate the correct runnable jar using eclipse's jar in jar loader. Feel free to add any libraries to the Rsrc-Class_Path (space seperated), also make sure your jars are in a folder called lib (or edit that part in the xml) and make sure jar-in-jar-loader.zip is next to your build.xml (or change it to an absolute location of that file, I think it is somewhere in the eclipse installation folder)

Note: this might require minor changes to suit your project.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="jar" name="Create Runnable Jar with Jar-in-Jar Loader">
    <property name="src" location="src"/>
    <property name="build" location="bin"/>
    <property name="dist" location="dist"/>
    <property name="lib" location="lib"/>

    <path id="master-classpath">
        <fileset dir="${lib}" includes="*.jar"/>
    </path>

    <target name="clean">
        <delete dir="${build}"/>
        <delete dir="${dist}"/>
    </target>

    <target name="compile" depends="clean" description="Compiles the project's source code">
        <mkdir dir="${build}"/>
        <javac srcdir="${src}" destdir="${build}" debug="on" source="1.5" target="1.5" includeantruntime="false">
            <classpath refid="master-classpath"/>
        </javac>
    </target>

    <target name="jar" depends="compile">
        <mkdir dir="${dist}"/>
        <jar destfile="${dist}/aGameName.jar">
            <manifest>
                <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
                <attribute name="Rsrc-Main-Class" value="net.aGameName.Game"/>
                <attribute name="Class-Path" value="."/>
                <attribute name="Rsrc-Class-Path" value="./ lwjgl.jar lwjgl_util.jar"/>
            </manifest>
            <zipfileset src="jar-in-jar-loader.zip"/>
            <fileset dir="${build}"/>
            <zipfileset dir="${lib}" includes="*.jar"/>
        </jar>
    </target>

</project>
share|improve this answer
up vote 1 down vote accepted

I actually found a small little program that would allow me to join multiple jar files together. I used this along with all the dependencies I needed and the jar that Eclipse generated to create a runable jar. Simple enough and for this small project it works fine.

http://ninjacave.com/jarsplice

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.