After adding Slick jvm does not find Main class anymore - java

I am currently trying to build a simple java Game with Slick and Maven.
My Setup does work basicly. But when I extend my Main Class to be a Slick "BasicGame" I can't execute the jar anymore, promting this error message:
D:\workspace\GameTest\target>java -jar GameTest-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/BasicGame
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
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)
Caused by: java.lang.ClassNotFoundException: org.newdawn.slick.BasicGame
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)
... 12 more
Could not find the main class: gameTest.MyGame. Program will exit.
Before I did this everything executed just fine. The Pom.xml is copied from here.
the MyGame class looks like this:
...
imports
...
public class MyGame extends BasicGame {
...
empty implementations of BasicGame Methods
...
public static void main(String[] args){
System.out.println("Hello World");
}
}
Does anyone know why this error occures?

Does anyone know why this error occurs?
When you switched to using an executable jar, you created a situation where your dependent library - slick.jar - is no longer in your class path. Everything starts out OK because MyGame is in your jar file. But MyGame extends BasicGame which is not in your jar file. It is in slick.jar and your java command makes no reference to slick.jar.
Somehow you have to get all your dependencies back into your class path. For more information check out related question Is it possible to create an "uber" jar containing the project classes and the project dependencies as jars with a custom manifest file?
Just checked your pom.xml file - you'll have to integrate lwjgl and vecmath into your class path also.

Related

How to run Junit tests from command line on windows with no package?

I have a folder(which is where I am running all commands) called learning. Inside this folder, I have two files, one is called Driver.java which is a simple main class with a simple hello world method. The other file is DriverTest.java which has this code as shown below.
import static org.junit.Assert.*;
import org.junit.Test;
public class DriverTest {
#Test
public void test() {
fail("Not yet implemented");
}
}
Apart from this I have JUnit 4.13-beta jar inside the same learning folder.
Now I open command line in windows and go to learning folder location and run this command.
javac -cp junit-4.13-beta-1.jar;hamcrest-core-2.1-rc4.jar;. *.java
It didn't give me any errors, hence it has compiled both Driver and DriverTest java files.
Now I am trying to run the JUnit test using this command.
java -cp junit-4.13-beta-1.jar;hamcrest-core-2.1-rc4.jar;. org.junit.runner.JUnitCore DriverTest
But I am getting this error:
JUnit version 4.13-beta-1
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at org.junit.runner.Request.classes(Request.java:77)
at org.junit.runner.JUnitCommandLineParseResult.createRequest(JUnitCommandLineParseResult.java:116)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:77)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
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)
... 17 more
Why is my HamCrest jar not found? Its right there in the same folder right?
You only added the current directory to the classpath for compilation. This needs to also be done for test invocation, ie. ;. in windows :. on linux
java -cp junit-4.13-beta-1.jar;. org.junit.runner.JUnitCore DriverTest

Can not refer to class packed in Jar1 that zipped in Jar2 while running Jar2

I'm getting this weird issue when my colleague runs my Jar in JRE of same version as my development environment (Java1.7 + Eclipse Indiago).
Add a Jar to build path and refer to some Classes in this jar;
Compile, run the project as Java application successfully in Eclipse;
Export the project as Runnable Jar with option - 'Package required libraries into generated Jar'.
Run the exported Jar in command line 'java -jar xxx.jar' in my computer and get expected result.
Run the same Jar in another computer with same JRE but get something error like 'ClassNotFound' telling that the class referred from inner Jar can not be found, as shown below:
Exception in thread "main" java.lang.NoClassDefFoundError: com/test/commo
n/communication/BaseNotificationEvent
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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 java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)
Caused by: java.lang.ClassNotFoundException: com.test.common.communicatio
n.BaseNotificationEvent
at java.net.URLClassLoader$1.run(Unknown Source)
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 java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
The solution so far is to export runnable jar with option 'copy required libraries into sub-folder next to generated Jar', and this works both in my and another computer.
But I am not take this as ultimate solution for I have to transfer multiple files rather a single Jar while releasing my program...which seems not elegant ^_^

Error java.lang.IncompatibleClassChangeError: Implementing class

I have a Dynamic Web Project in Java and I use Jena and D2RQ libraries.
When I start my project as "Java Application", I have this problem:
Exception in thread "main"
java.lang.IncompatibleClassChangeError: Implementing class at
java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClass(Unknown Source) at
java.security.SecureClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.access$100(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) 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) at
de.fuberlin.wiwiss.d2rq.algebra.CompatibleRelationGroup.addNodeRelation(CompatibleRelationGroup.java:53)
at
de.fuberlin.wiwiss.d2rq.algebra.CompatibleRelationGroup.groupNodeRelations(CompatibleRelationGroup.java:38)
at de.fuberlin.wiwiss.d2rq.find.FindQuery.iterator(FindQuery.java:78)
at
de.fuberlin.wiwiss.d2rq.jena.GraphD2RQ.graphBaseFind(GraphD2RQ.java:88)
at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240) at
com.hp.hpl.jena.graph.compose.DisjointUnion.graphBaseFind(DisjointUnion.java:27)
at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240) at
com.hp.hpl.jena.graph.impl.GraphBase.graphBaseFind(GraphBase.java:260)
at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257) at
com.hp.hpl.jena.graph.query.SimpleQueryHandler.predicatesFor(SimpleQueryHandler.java:68)
at
com.hp.hpl.jena.graph.query.SimpleQueryHandler.predicatesFor(SimpleQueryHandler.java:47)
at
com.hp.hpl.jena.rdf.model.impl.ModelCom.listPredicates(ModelCom.java:751)
at
com.hp.hpl.jena.rdf.model.impl.ModelCom.listNameSpaces(ModelCom.java:763)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.addNameSpaces(BaseXMLWriter.java:233)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.setupNamespaces(BaseXMLWriter.java:487)
at
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:469)
at MyPackage.MyClass.Mymethod(MyClass.java:118) at
MyPackage.Test.main(Test.java:77)
The row 118 of the class "MyClass" contains this code:
writer.write(d2rqModel, new OutputStreamWriter(out, "utf-8"),loader.getResourceBaseURI());
with
RDFWriter writer;
and
import com.hp.hpl.jena.rdf.model.RDFWriter;
Why I have this problem?
In addition, the same class in a different project works well!!! Why?
You've changed and recompiled the class without recompiling everything that depends on it. Do a clean build. You may get some compiler errors in the process.
You may have added dependency that are ambiguous to compiler's understanding. Verify that you don't have duplicate dependency for same class.

Error running .class files

I wonder why the Game.class wont start. Here's he problem I got:
java.lang.NoClassDefFoundError: Game (wrong name: game/Game)`
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Exception in thread "main"
You will get similar error if you do mething like this:
package game;
class Game
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
without putting the compiled class file in a sub-folder called game and run it like java Game. So your Game class is in a package called game.
Please Check Your packaging structure and ensure that your class file is inside the package folder . Compile and Happy Execution ....

What's wrong with this .jar file?

I'm trying to turn my JoGL project into a jar file. What am I doing wrong?
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/opengl/GL
EventListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.media.opengl.GLEventListener
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 12 more
Could not find the main class: chartest. Program will exit.
Contents of the JAR file:
META-INF\MANIFEST.MF
gluegen-rt.jar
jogl.jar
chartest$1.class
chartest.class
gluegen-rt.dll
jogl.dll
jogl_awt.dll
jogl_cg.dll
test.png
You can check your classpath. It should include atleast
The jar file with classes you have written
Supporting jars with classes like javax.media.opengl (jogl.jar?)
Try placing all these jars in your classpath and run it.
is Jogle jar file in your classpath ?
I see you have included the jars themselves in your jar... this unfortunately wil not work out of the box.
Either get the jars out then place in your classpath (that can be part of your manifest also) or write your own classloader...
http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html
This is why it worked for William and not for you... he got the jogl from somewhere else and did not use the one within your jar.
Switch to Netbeans to build your jar file. I find using other libraries inside of my projects including dll files its best to use something like Netbeans or just package it with maven.
mvn clean package
You need to be well versed in xml though if you want to use maven to package all of your jar files.

Categories

Resources