Java 3D in eclipse Mac OSX not functioning

classic Classic list List threaded Threaded
63 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
Thanks for your help once again. Have just been googling the manifest option and impacts on classpath and becoming slightly confused. Could you send me a link to the paragraph you mention please?

Just so you know what I am doing in case I am making other mistakes. I have a jar created in eclipse on a PC. The manifest file simply says:

Manifest-Version: 1.0
Main-Class: main.MyDriver
SplashScreen-Image: images/splash.jpg

This works fine on a PC, and simply needs to run on a Mac. Other Java (non Java3D) programs I have run fine on a mac by simply double clicking the relevant jar file. However this doesnt work in Java3D on a Mac. All I want to do is to get my Jar to run on my friends Mac - ideally via a double click. Will this be possible with the current Java3D / Mac OS systems?

When you say 'update the classpath attribute of the manifest' could you give me a tip please. And surely if I affected the classpath via the manifest file this would have an impact on the jar files portability?


Dont worry, your blog instructions are the clearest information I have found and are much appreciated. There is a lot of conflicting advice out there, due to the various versions that have been run of Java3D over the years. As said, I have been through the Mac and cleared all the dirty installs I have put in, to the best of my knowledge. I have been using Java3D for nearly 10 years and so unfortunately the old ways of installing the various old versions have become common, and were the first things I tried due to habit with PC's. They also work fine on a PC, and I am not a normal Mac user, and having spent far too much of my time on this problem already am unlikely to become one:-)
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

jmaasing
def: Executable JAR is a jar you can run using 'java -jar myexectuable.jar'
When you use '-jar' the '-cp' argument is ignored:
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html#BABDJJFI

So how to handle all the other JAR-files your project needs?
There are two 'clean' ways:
1) Package your application as a ZIP-file, include your executable jar. Then include all the other JAR-files in for example a 'lib' directory. Then you set up the MANIFEST.MF file in your executable JAR to point to the lib-directory. See documentation on MANIFEST.MF for details.

2) Make a "fat"-jar. That means you unpack _all_ jar-files into a single directory and then JAR that directory together. Every class-file ends up in a single JAR-file. This sounds good but it is not without problems. There have been many discussions on these forums about this.

There is an 'unclean' way. Install the dependencies in a boot classpath or 'ext' directory in the JVM. I've heard that jogl has been included in Apple JVM this way. Also, this was a a recommended way to install Java3D a long time ago. This has many, many, many problems with conflicting versions et c since the JVM will favour these classes regardless of what an application packages. This should be avoided at all cost.
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

gouessej
Administrator
In reply to this post by everythingConnected
Hi

everythingConnected wrote
Thanks for your help once again.
You're welcome.

everythingConnected wrote
Have just been googling the manifest option and impacts on classpath and becoming slightly confused. Could you send me a link to the paragraph you mention please?
http://www.manpagez.com/man/1/java/
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
This webpage indicates how to add files to the JAR's classpath (by modifying the manifest attribute "Class-Path"):
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

I don't want to be harsh but I advise you to read correctly the documentation of the commands that you want to use.

everythingConnected wrote
Just so you know what I am doing in case I am making other mistakes. I have a jar created in eclipse on a PC. The manifest file simply says:

Manifest-Version: 1.0
Main-Class: main.MyDriver
SplashScreen-Image: images/splash.jpg

This works fine on a PC, and simply needs to run on a Mac. Other Java (non Java3D) programs I have run fine on a mac by simply double clicking the relevant jar file. However this doesnt work in Java3D on a Mac. All I want to do is to get my Jar to run on my friends Mac - ideally via a double click. Will this be possible with the current Java3D / Mac OS systems?
At first, I advise you to use Ant in Eclipse to create your JAR as it's safer and it gives you a lot of control on the creation. Using Eclipse as a black box without trying to understand what happens inside will lead you nowhere except for extremely simple applications with no external dependencies.

Secondly, you're probably doing something else wrong, it shouldn't find magically your libraries even on a PC. You should read this section of my article even though it has been written for another engine, most of it still applies for Java3D:
https://gouessej.wordpress.com/2014/11/22/ardor3d-est-mort-vive-jogamps-ardor3d-continuation-ardor3d-is-dead-long-life-to-jogamps-ardor3d-continuation/#deployment
The paragraph entitled "Executable JAR" lists tons of limitations that you seem to ignore.

everythingConnected wrote
When you say 'update the classpath attribute of the manifest' could you give me a tip please. And surely if I affected the classpath via the manifest file this would have an impact on the jar files portability?
Clean up your PC and you will exhibit mostly the same behaviour than on a Mac. Look at my answer above, especially the second link I gave you.

everythingConnected wrote
Dont worry, your blog instructions are the clearest information I have found and are much appreciated. There is a lot of conflicting advice out there, due to the various versions that have been run of Java3D over the years. As said, I have been through the Mac and cleared all the dirty installs I have put in, to the best of my knowledge. I have been using Java3D for nearly 10 years and so unfortunately the old ways of installing the various old versions have become common, and were the first things I tried due to habit with PC's. They also work fine on a PC, and I am not a normal Mac user, and having spent far too much of my time on this problem already am unlikely to become one:-)
There are lots of confusing instructions due to the stupidity and the selfishness of some bloggers who are more interested in earning money from ads than providing accurate and updated information. In some cases, some developers have bad habit and/or take themselves for experts. I fear that you "installed" Java3D somewhere on your PC and it is picked up, it won't work on some other PCs. I'm still open to suggestions, nothing is perfect.

Keep in mind that as the public API of Java3D is frozen, there will ever be some machines on which it won't work because of unresolvable conflicts when you use the JVM installed on the system. What you did on a single Mac shouldn't or can't be done on all Macs of your end users. There are some tricks to work around this limitation, for example Runiter explained how to rename the packages of Java3D so that OS X never makes a confusion between the obsolete version of Java3D and the latest one.

Finally, you probably want to create a single JAR containing both your application and its dependencies as you talked about running it by a double click. It's explained in the very last link I gave you. OS X itself will annoy you, I mean that Gatekeeper might block your application, I had to update my instructions about this concern:
http://tuer.sourceforge.net/en/play/
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
Thanks for the help for all who have replied, as I have now managed to get my 3D application to run on a Mac, which is great.

Firstly I was not aware that when running a -jar file then any -cp argument is ignored. My mistake but its simply not something I needed to know before. Learn by experience once again I guess.

For anyone in a similar situation then I have got this to work by following the above advice, adding all the relevant Java3D, jogl etc. jar files to a 'lib' folder, and including these in the manifest file of my jar file. Then running my jar file as normal, which avoids the classpath problem I had created above. This lib folder obviously needs distributing with the application but thats no problem, and actually has numerous benefits such as not needing the user to pre-install Java3D.

Whats interesting is that this still does not work on the Mac I have been using to try and get Java3D to work on previously, but it does work on another 'clean' Mac i have just borrowed. This means that, as suggested, there are old libraries somewhere that is stopping the new Java3D system from working. This has been well described in Juliens blog and I have spent a lot of time trying to find any of these files without success, so for anyone reading this thread who has similar problems then the conclusion is either:

a) I have installed some old Java3D files that I now cannot find again, which is possible but unlikely as I have spent a lot of time checking.

b) The Mac I installed the old version on has either hidden these files or has copied them to somewhere else that I now cannot find.

I am now going to give up trying to get Java3D to work on the original Mac as it was just a test machine. If it had to work then I would now be looking at firstly uninstalling all Java from the machine and deleting everything I could relating to it, and if that doesnt work then I would have to re-install the operating system.

Appreciate the comments regarding general usage of jar files etc. As with all these things you learn by experience, and I am still learning.

Am now onto another problem with the Mac in that I used to run the jar file on windows from a .bat script so they could be run by a double click. Somehow this doesnt seem as simple on a Mac with either .sh or .command files. Time for more Mac learning....
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

gouessej
Administrator
everythingConnected wrote
Somehow this doesnt seem as simple on a Mac with either .sh or .command files. Time for more Mac learning....
The bash script should work, this is what I use inside my self-contained native application bundle for Mac (bzipped APP file).

Edit.: I don't know how your project is licensed. If it's under GPL, just use my tools to create your bundle, otherwise have a look at PackR, at least to understand how it creates a APP "file". Run your script in command line to see what is wrong. The Mac Sven gave me is dying, I have no Mac to help you :s
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
Just tying to run it using a .command file so its double click-able. Its equivalent in Windows would basically be:

#!/bin/bash
java -jar MyJar.jar

This doesnt work in Mac world, seemingly as the script does not run in the directory it is currently in (same one as the jar), but in a home directory. Lots of info on google about such thing but any attempt to change its current directory doesnt seem to work to me using commands such as:

cd “$(dirname “$0”)” or cd “$(dirname “${BASH_SOURCE[0]}” )”

I can get the thing to run fine from the terminal window itself, but then I have navigated to the correct directory. Somehow the seemingly simple idea of double clicking a script file and having it execute in the directory it is in seems very complicated in Mac world...



 
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

gouessej
Administrator
I use a similar script:
http://stackoverflow.com/a/246128

It works like a charm, I tested it a few months ago under Mac OS X 10.6.8 and jmaasing tested it on a much more recent Mac.

Edit.: If it doesn't work, use a native executable with PackR instead of a Bash script.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
Thanks, and had seen that link but I cant get it to work. Not sure why but think its something to do with dirname, which seems to return an empty string. This may be because I am running it from the directory it is located in but again not sure.

Still amazed that on a Mac i cant write a very simple script that simple runs a jar file from the directory it and the script are in using the line: java -jar MyJar.jar, via a double click. This is 2 minute job in non-Mac world...

Could you give me a link to PackR please? i have been looking at things such as JarLauncher and other tools but they all seem depreciated or have issues somewhere.
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

jmaasing
I just tried this for my toy-application "nightfly" - substitute for you app name where applicable.

Create the application directory structure:
nightfly.app/Contents/MacOS

Create this file:
nightfly.app/Contents/Info.plist

with this content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
  <dict>
   
    <key>CFBundleName</key>
    <string>Nightfly</string>
   
    <key>CFBundleExecutable</key>
    <string>nightfly</string>
   
    <key>CFBundlePackageType</key>
    <string>APPL</string>
   
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
  </dict>
</plist>


Then create this script file:
nightfly.app/Contents/MacOS/nightfly

Make it executable (e.g. chmod +x nightfly)

This is the script content:
#!/bin/sh
PRG="$0"

if [ -x "/usr/libexec/java_home" ]; then
        jdkhome=`/usr/libexec/java_home`
fi

if [ ! -x "${jdkhome}/bin/java" ] ; then
    echo "Cannot find java." >&2
    exit 2
fi
progdir=`dirname "$PRG"`
APPNAME=`basename "$PRG"`

echo "progdir $progdir, appname: $APPNAME"
cd $progdir && ${jdkhome}/bin/java -jar nightfly-1.0-SNAPSHOT.jar


As you can guess the executable jar is in nightfly.app/Contents/MacOS

The executable jar has a manifest classpath pointing to lib/jogl......jar and all that jazz, the lib directory is beside the executable jar.

You should be able to use a console to run "nightfly.app/Contents/MacOS/nightfly"
if that works try:
"open nightfly.app"

If that works you should be able to double click to start it it as any OSX application

If you want application icons and such you should look at the docuemntation for Info.plist in the Apples developer documentation. But then again you might be better off looking at for example JavaFX-launchers, or how jMonkeyEngine creates launcher, or look at PackR (it's a libgdx-project), launch4j or similar projects.
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

gouessej
Administrator
This post was updated on .
In reply to this post by everythingConnected
jmaasing explained it pretty well and my tutorial contains those links, you should have read it better...

Look at this and this but jmaasing's suggestion is more simple, you should investigate on it first.

In my humble opinion, there is probably something small that prevents your script from working, maybe it picks a JVM incompatible with JogAmp. Writing a script for Mac is almost as easy as for GNU Linux and Windows. The problems come when you want to use the system JRE and when Gatekeeper prevents your application from running. jmassing's suggestion will help you to find out the culprit.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
Thanks for the help again. I now have it all running fine, after quite some headaches and a steep learning curve regarding use of Macs.

I think one mistake I made was writing the scripts on a PC and then moving them onto the Mac - not surprising since I work on a PC and had just borrowed a friends Mac to test, but I suspect there were some Windows characters in the script stopping it working. In the end, once I had created the script from scratch on the Mac, then the line: cd "$(dirname "0")" works fine, as do the other suggestions above.
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

gouessej
Administrator
I write my scripts under GNU Linux and they work very well under OS X and Windows. You should take care of the encoding. Which editor do you use under Windows?

My suggestion allows to work around some limitations.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
I had probably started them in Notepad under Windows so suspect the encoding there was causing problems with Mac OS X, as once written on a Mac from scratch then they worked as expected.
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

jmaasing
I'm 99,99% sure it is the line endings tripping you up. You should use a real editor that allows to set the line endings when writing scripts :-)
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
Yes, I think you are right from what I learned from google, when eventually figured it out. Another lesson learned:-)
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

gouessej
Administrator
everythingConnected wrote
Yes, I think you are right from what I learned from google
Google Search teaches nothing, it's just a search engine. When you look for something, you still need to know how to do that and how to evaluate the pertinence of the source. Moreover, there are other search engines and you're not forced to "promote" Google for free, work must pay.

everythingConnected wrote
, when eventually figured it out. Another lesson learned:-)
Using Notepad++ instead of Notepad should solve your problem. Its fifth menu allows to select the encoding and you can probably choose the line ending character too.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

everythingConnected
Yes, Notepad++ is very useful. Thats what showed me the line ending problem with my own eyes. And fair point re.google.
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

sotillo19
In reply to this post by gouessej
Hi gouessej, I am having a similar problem to this thread. I have spent several days following your instructions without success :(

I have a Java 3D application I wrote 2 years ago which I am trying to get to work on a Mac (Yosemite) with the JDK 8 from Oracle using Eclipse. The application still runs fine on my pc (Windows 8.1) with Eclipse too.

Following your instructions, I have downloaded the JARs for JOGL, JOAL and GlueGen from http://jogamp.org/deployment/jogamp-current/archive/jogamp-all-platforms.7z and http://jogamp.org/deployment/java3d/1.6.0-pre11/jogamp-java3d.7z and extract them into a directory in my home and finally I have added all jars except "native" into CLASSPATH:

echo $CLASSPATH
.:/Users/sotillo/j3d/j3dcore.jar:/Users/sotillo/j3d/j3dutils.jar:/Users/sotillo/j3d/vecmath.jar:/Users/sotillo/j3d/gluegen-rt.jar:/Users/sotillo/j3d/joal.jar:/Users/sotillo/j3d/jocl.jar:/Users/sotillo/j3d/jogl-all.jar:/Users/sotillo/j3d/gluegen.jar:/Users/sotillo/j3d/jogl-all-noawt.jar

I have also added the jars into Java Build Path in Eclipse and no old jars of Java3d there are in /Library/Java/Extensions/. However, when I run my application, this is the exception:
3D [dev] 1.6.0-pre11-daily-experimental daily

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/media/opengl/GLException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at javax.media.j3d.Pipeline$PipelineCreator.run(Pipeline.java:74)
        at javax.media.j3d.Pipeline$PipelineCreator.run(Pipeline.java:61)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.media.j3d.Pipeline.createPipeline(Pipeline.java:91)
        at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:837)
        at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:274)
        ....

Any help gratefully received. I am only trying to get this to work on a mac, I am frustrated at having spent several days on this problem, and have tried to follow your instructions in your blog as well as possible.

Thanks in advance!
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

gouessej
Administrator
Hi

I've just updated my tutorial, please press CTRL+R if it is not refreshed, it is written in red. You have to use Java3D with JOGL 2.2.0 as Harvey hasn't updated it for JOGL 2.3.0, which is why I "complained":
http://forum.jogamp.org/Java3D-not-yet-compatible-with-JOGL-2-3-0-td4034187.html

Thank you for your feedback.

Edit.: I'm sorry, don't hesitate to contact us immediately when something is wrong in order to avoid spending days in investigating if something "obvious" is broken.

Edit.2: Don't use jogl-all-noawt.jar, use only jogl-all.jar as it is mentioned in my tutorial!
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java 3D in eclipse Mac OSX not functioning

sotillo19
Hi again,

   thanks so much! I just use JOGL 2.2.0 and Java3D 1.6 pre-build 11 and it works!! :)

   Again, thank you very much! It is a privilege that there are people like you that help the rest to solve their problems.

1234