问题
This is my Javac compiling statement:
javac -cp "C:\java\code\j3D\j3dcore.jar;C:\java\code\j3D\j3dutils.jar;C:\java\code\j3D\vecmath.jar" Simple.java
- compiles with no problems.
The three jar files (j3dcore
, j3dutils
, and vecmath
) are the essential jar's for my program (or at least I am led to believe according to this official tutorial on J3D
For the record I ripped this code almost line from line from the above pdf file.
- jar files are correctly located in referenced locations
When I run my Simple
program, (java Simple
) I am greeted with
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/Cavas3d Caused by: java.lang.ClassNotFoundExpection: javax.media.j3d.Canvas3D
Currently I am staring directly at this Canvas3D.class
that is located within j3dcore.jar\javax\media\j3d\
wtfisthis.jpg
Here is the source code:
//First java3D Program
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.GraphicsConfiguration;
public class Simple extends Applet {
public Simple() {
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);
add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
scene.compile();
// SimpleUniverse is a Convenience Utility class
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
// This moves the ViewPlatform back a bit so the
// objects in the scene can be viewed.
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
} // end of HelloJava3Da (constructor)
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create a simple shape leaf node, add it to the scene graph.
// ColorCube is a Convenience Utility class
objRoot.addChild(new ColorCube(0.4));
return objRoot;
}
public static void main(String args[]){
Simple world = new Simple();
}
}
- Did I import correctly?
- Did I incorrectly reference my jar files in my Javac statement?
- If I clearly see
Canvas3D
within its correct directory why cant java find it? - The first folder in both
j3dcore.jar
andvecmath.jar
is "javax". Is the compiler getting confused? - If the compiler is getting confused how do I specify where to find that exact class when referencing it within my source code?
回答1:
try:
java -cp "C:\java\code\j3D\j3dcore.jar;C:\java\code\j3D\j3dutils.jar;C:\java\code\j3D\vecmath.jar" Simple
you need to include the classpath on the java
commandline as well.
回答2:
Just doing java simple
wont help. You need to put all those jars in classpath while you run the program. Just like you did to compile it.
java -cp C:\java\code\j3D\j3dcore.jar;C:\java\code\j3D\j3dutils.jar;C:\java\code\j3D\vecmath.jar Simple
Please Check Setting the class path
来源:https://stackoverflow.com/questions/10827452/why-am-i-getting-classnotfoundexpection-when-i-have-properly-imported-said-class