Getting Java3d to work on OS X on IntelliJ

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting Java3d to work on OS X on IntelliJ

Zahand
So I have ben trying to get Java3D to work on IntelliJ so I can do the mandatory assignments for class (Studying Computer Science). But I have had some problems. (Here is a copy of the stackoverflow post I made: http://stackoverflow.com/questions/26378249/how-to-get-java3d-to-work-in-intellij-on-os-x?noredirect=1)


I use IntelliJ as my IDE and it works great for Java and Python. But I am struggling to make it work for Java3D.

I've tried using my google-fu but to no avail. So I am coming here for some guidance. I have tried multiple tutorials/guides, here is what I have tried:


The code I am trying to run is from http://www.java3d.org/starting.html


    import com.sun.j3d.utils.universe.SimpleUniverse;

    import com.sun.j3d.utils.geometry.ColorCube;

    import javax.media.j3d.BranchGroup;

    public class Hello3d {

        public Hello3d(){

        SimpleUniverse universe = new SimpleUniverse();

        BranchGroup group = new BranchGroup();

        group.addChild(new ColorCube(0.3));

        universe.getViewingPlatform().setNominalViewingTransform();

        universe.addBranchGraph(group);

        }

    public static void main( String[] args ) {

        new Hello3d();

        }

    }


First thing I tried was installing the Java3d Jar's and adding them to the dependencies: (I got them from: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-client-419417.html#java3d-1.5.1-oth-JPR

But I got the error:

    Exception in thread "J3D-Renderer-1" java.lang.NoClassDefFoundError: apple/awt/ComponentModel
            at com.sun.opengl.impl.JAWT_DrawingSurface.GetDrawingSurfaceInfo0(Native Method)
    at com.sun.opengl.impl.JAWT_DrawingSurface.GetDrawingSurfaceInfo(JAWT_DrawingSurface.java:56)
            at com.sun.opengl.impl.macosx.MacOSXOnscreenGLDrawable$1.run(MacOSXOnscreenGLDrawable.java:165)
    at java.security.AccessController.doPrivileged(Native Method)
            at  com.sun.opengl.impl.macosx.MacOSXOnscreenGLDrawable.lockSurface(MacOSXOnscreenGLDrawable.java:163)
    at com.sun.opengl.impl.macosx.MacOSXOnscreenGLContext.makeCurrentImpl(MacOSXOnscreenGLContext.java:57)
            at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
            at javax.media.j3d.JoglPipeline$QueryCanvas.doQuery(JoglPipeline.java:9049)
            at javax.media.j3d.JoglPipeline.getBestConfiguration(JoglPipeline.java:8797)
            at javax.media.j3d.Renderer.doWork(Renderer.java:514)
            at javax.media.j3d.J3dThread.run(J3dThread.java:275)
    Caused by: java.lang.ClassNotFoundException: apple.awt.ComponentModel
            at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
            at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 11 more

Then I learned that java3d is already installed on mac and I did the same. I added the jars to my dependencies. But I got the same error.


My last attempt was to follow this guide: http://gouessej.wordpress.com/2012/08/01/java-3d-est-de-retour-java-3d-is-back/ 

I downloaded the jars, put them all in the same folder and added them to my dependencies. But, again, I got the same error.


Now, it might be all my fault (I am not sure if I have to add them to my dependencies then add new Jars, but it always worked when I added different kind of API's) or it might be something more complex. Hopefully some of you guys have encountered the same issues and can help me.

Thanks in advance.

----------------


Edit: After trying what gouessej said, I got this error:

    JavaVM WARNING: JAWT_GetAWT must be called after loading a JVM
    AWT not found
    Exception in thread "main" java.lang.NoClassDefFoundError: apple/awt/CGraphicsDevice
    at javax.media.j3d.GraphicsConfigTemplate3D.<clinit>(GraphicsConfigTemplate3D.java:55)
    at com.sun.j3d.utils.universe.SimpleUniverse.getPreferredConfiguration(SimpleUniverse.java:368)
    at com.sun.j3d.utils.universe.Viewer.<init>(Viewer.java:348)
    at com.sun.j3d.utils.universe.Viewer.<init>(Viewer.java:298)
    at com.sun.j3d.utils.universe.SimpleUniverse.<init>(SimpleUniverse.java:215)
    at com.sun.j3d.utils.universe.SimpleUniverse.<init>(SimpleUniverse.java:177)
    at com.sun.j3d.utils.universe.SimpleUniverse.<init>(SimpleUniverse.java:88)
    at MAIN.<init>(MAIN.java:22)
    at MAIN.main(MAIN.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
    Caused by: java.lang.ClassNotFoundException: apple.awt.CGraphicsDevice
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
            ... 14 more

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

gouessej
Administrator
Hi

Sorry but an old version of Java3D is still installed on your machine, this old version calls apple/awt/CGraphicsDevice whereas the latest version doesn't depend on this class, it's explained in this section of the tutorial:
http://gouessej.wordpress.com/2012/08/01/java-3d-est-de-retour-java-3d-is-back/#troubleshooting

Moreover, check that you really use the JARs I mention in my tutorial. If you use (by mistake) Oracle JARs, it won't work. Another developer made this kind of mistake:
http://forum.jogamp.org/Java-3D-in-eclipse-Mac-OSX-not-functioning-tp4033010p4033039.html

My tutorial is correct, I spent tens of hours to write it. I mentioned most of the possible directories in which Java3D is installed by default under OS X but I can do nothing for you if it was manually installed elsewhere, you have to look for its JARs.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

Zahand
Hello. My teacher helped me, and all I had to do, was to use the Java 1.6 JDK and not 1.8.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

gouessej
Administrator
No it isn't the right solution, it just picks the old version of Java3D (1.5) and use it with the "old" version of Java (Apple Java 1.6). It confirms what I wrote. Java3D 1.6 is compatible with Oracle Java 1.8. Your teacher is wrong, it is "the easy way" because as the Apple JVM will be abandoned, your program won't work in OS X versions with no Apple JVM.

Edit.: If you post this kind of "solution" on StackOverflow, I will downvote it because it will only confuse other developers. The right solution consists in knowing what you install on your machine, uninstall the old version of Java3D and then install the new version of Java3D.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

Zahand
I did try removing the old version, but then I got the error on the bottom of the original post.

Edit: I will try once more.


Here is what I have in my /Library/Java/Extensions folder

http://i.imgur.com/GFWymCv.png?1

What exactly should I remove and replace with the Jars you provided in your guide?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

gouessej
Administrator
You should remove all these JARs, j3dcore, vecmath, j3dutils, gluegen-rt, jogl, ... You should check whether there are the same JARs in another location.

You mustn't put install any library as an extension, don't put any JARs into the "Extensions" directory, it is a dangerous method. My instructions state that. Just put the JARs elsewhere, neither in the JVM, nor in the extensions directories.

Thank you for your nice feedback, I will improve my tutorial :)

Edit.: Maybe you'll be able to teach something to your teacher then, I find that exciting :) You'll be proud of yourself ;)

Edit.2: Apple Java 1.6 is deprecated:
https://developer.apple.com/library/mac/releasenotes/Java/JavaSnowLeopardUpdate3LeopardUpdate8RN/NewandNoteworthy/NewandNoteworthy.html#//apple_ref/doc/uid/TP40010380-CH4-SW1
Please use Java 1.8 (OpenJDK or Oracle Java).
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

Zahand
All the jars have been removed. I have downloaded the jars you provided in your guide (
j3dcore.jar
j3dutils.jar
vecmath.jar

and the JARs for JOGL, JOAL and GlueGen)

I put all the necessary jars into one folder like this:
http://imgur.com/uEg7kjI


Now, I assume I should add these jars to my dependencies and all should work fine (using Java 1.8)?


Edit: I tried it and I got the error "Exception in thread "main" java.lang.NoClassDefFoundError: apple/awt/CGraphicsDevice"

In your troubleshooting-page you said I needed to remove the old java 3d files, but I already did that...

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

gouessej
Administrator
This post was updated on .
The old JARs can be in multiple locations. Java3D 1.6 and JOGL 2 never use apple/awt. Look at the "installation" section, it gives a list of the possible directories.

Edit.: You can try to use the last trick of the "troubleshooting" section, it allows to skip the extensions.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

Ajay Shrestha
In reply to this post by gouessej
Thank you. It works. You save my time :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting Java3d to work on OS X on IntelliJ

gouessej
Administrator
You're welcome. It works even better with Java3D 1.7.0.
Julien Gouesse | Personal blog | Website
Loading...