0

I'm making a project that imports X3D files into Java and displays them. However, when I run it, I get the runtime error

run:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/Canvas3D
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.web3d.j3d.browser.X3DJ3DBrowserFactoryImpl.createComponent(X3DJ3DBrowserFactoryImpl.java:358)
    at org.web3d.x3d.sai.BrowserFactory.createX3DComponent(BrowserFactory.java:263)
    at xj3dtest.Xj3DTest.<init>(Xj3DTest.java:42)
    at xj3dtest.Xj3DTest.main(Xj3DTest.java:56)
Caused by: java.lang.ClassNotFoundException: javax.media.j3d.Canvas3D
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 16 more

The Java code I have is

package xj3dtest;

import java.awt.BorderLayout;
import java.awt.Container;
import static java.lang.Boolean.TRUE;
import javax.swing.JFrame;
import org.web3d.x3d.sai.Browser;
import org.web3d.x3d.sai.BrowserFactory;
import org.web3d.x3d.sai.X3DComponent;
import org.web3d.x3d.sai.X3DScene;
import java.util.HashMap;

public class Xj3DTest extends JFrame {

    public Xj3DTest(String title) {

        super(title);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Setup browser parameters
        HashMap requestedParameters=new HashMap();
        requestedParameters.put("Antialiased",TRUE);
        requestedParameters.put("TextureQuality","medium");
        requestedParameters.put("PrimitiveQuality","medium");
        requestedParameters.put("Xj3D_InterfaceType","SWING");
        requestedParameters.put("Xj3D_NavbarShown",TRUE);
        requestedParameters.put("Xj3D_NavbarPosition","TOP");
        requestedParameters.put("Xj3D_LocationShown",TRUE);
        requestedParameters.put("Xj3D_LocationPosition","TOP");
        requestedParameters.put("Xj3D_LocationReadOnly",TRUE);
        requestedParameters.put("Xj3D_ShowConsole",TRUE);
        requestedParameters.put("Xj3D_OpenButtonShown",TRUE);
        requestedParameters.put("Xj3D_ReloadButtonShown",TRUE);
        requestedParameters.put("Xj3D_StatusBarShown",TRUE);
        requestedParameters.put("Xj3D_FPSShown",TRUE);
        requestedParameters.put("Xj3D_ContentDirectory","CurrentDirectory");
        requestedParameters.put("Xj3D_AntialiasingQuality","low");
        requestedParameters.put("Xj3D_Culling_Mode", "frustum");

        System.setProperty("x3d.sai.factory.class", "org.web3d.j3d.browser.X3DJ3DBrowserFactoryImpl");
        X3DComponent x3dComponent = BrowserFactory.createX3DComponent(requestedParameters);

        Browser browser = x3dComponent.getBrowser();

        Container cp = getContentPane();
        cp.setLayout(new BorderLayout());
        cp.add((javax.swing.JPanel)x3dComponent, BorderLayout.CENTER);

        X3DScene scene = browser.createX3DFromURL(new String[] {"test.x3d"});

        browser.replaceWorld(scene);
    }

    public static void main(String[] args) {
        Xj3DTest frame = new Xj3DTest("Xj3D test");
        frame.setSize(640, 480);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

The Jars that I have are: gluegen-rt, gluegen-rt-natives-linux-amd64, gluegen-rt-natives-windows-amd64, gluegen-rt-natives-windows-i586, jhall, joal, joal-natives-linux-amd64, joalnatives-windows-amd64, gluegen-natives-windows-i586, jogl-all, jogl-natives-linux-amd64, jogl-natives-windows-amd64, jogl-natives-windows-i586, xj3d.browser_2.1.0-nps, xj3d.cadfilter_2.1.0-nps, xj3d.replica_2.1.0-nps, xj3d-2.1-3rdparty-nps, xj3d-2.1-nps, xj3d-core, xj3d-j3d all within a file called jar. Within the VM Options in the Run section of the Jave project I have -Xmx450M -Djava.library.path="C:\Users\matt\Documents\NetBeansProjects\jar"

Any help would be great.

smitthy
  • 307
  • 4
  • 18
  • 1
    `javax/media/j3d/Canvas3D` should be the old location, update your `imports` – elect Apr 12 '16 at 16:49
  • @elect Thanks, however now I've got the error `Exception in thread "main" java.lang.UnsatisfiedLinkError: no J3D in java.library.path` – smitthy Apr 12 '16 at 17:05
  • you should add the path to `J3D` to your path. You can do this by adding the option in the project properties in your IDE – elect Apr 12 '16 at 20:29
  • @elect How would I go that? I have the `project properties` open and on the `Run` bit. I've added `-Xmx450M -Djava.library.path="C:\Users\matt\Documents\NetBeansProjects\J3D jar"` as I've downloaded `j3d-org-java3d-all.jar` as that's where it's saved – smitthy Apr 12 '16 at 20:52
  • Yep, with `-Djava.library.path`. I think you are not pointing what it wants... have you already checked [that](http://stackoverflow.com/questions/4098161/problems-with-java3d-lib-configuration)? – elect Apr 13 '16 at 06:32
  • @elect how would I make it to point to where it wants? – smitthy Apr 13 '16 at 15:13
  • I have no idea, but I guess you should insert there a path containing a lib or something similar – elect Apr 13 '16 at 15:35
  • @elect do you think I should use some `jars` that might help? – smitthy Apr 13 '16 at 15:43
  • I am sorry but I don't know. Anyway, if you need to import x3d files, I am working on a java porting of Assimp [here](https://github.com/elect86/jAssimp). If you want we can collaborate together and add x3d support – elect Apr 13 '16 at 16:31
  • @elect May I ask what your project `Assimp` is? As I have got an output of `X3D` files that don't include any `viewpoint` or `imageTexture URL` tags – smitthy Apr 13 '16 at 20:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109109/discussion-between-elect-and-smitthy). – elect Apr 14 '16 at 06:17
  • I'd have to revise the Jogamp Java3D installation, but after the installation, there should be a Java3D directory. This directory (or one of its subdirectories) should contain a `J3D.DLL` (Windows). And your `java.library.path` should point to the directory that contains this DLL file. For example, something like `-Djava.library.path="C:\Program Files\Java\Java3D\bin"` (**IF** this is the directory that contains the DLL). The `java.library.path` should *not* refer to a JAR file, but to the *directory* that contains the DLL. – Marco13 Apr 20 '16 at 10:45
  • @elect I have a similar problem found http://stackoverflow.com/questions/36802346/exception-in-thread-main-java-lang-noclassdeffounderror-org-web3d-browser-bro and I don't know why I'm getting the error – smitthy Apr 22 '16 at 20:14
  • I am really sorry, but I never worked with java3d, I can't help you. Try to write on this [thread](http://forum.jogamp.org/Java3d-1-6-0-pre12-released-requires-jogl-2-3-1-td4034327i20.html) or similar, they might be able to help you – elect Apr 22 '16 at 20:58

0 Answers0