Simbad requires Java 3D - classpath

Context:
MS Windows 8,
jre7 preinstalled by MS Windows setup,
MS Windows PATH environment variable has set to JRE7 bin folder - C:\Program Files (x86)\Java\jre7\bin,
simbad-1.4.jar is downloaded into a local folder.
Use cases:
simbad-1.4.jar is run by command line
java -jar simbad-1.4.jar
or by just double-clicking on simbad-1.4.jar
In both cases
Simbad requires Java 3D
error message box appears.
Yes, I know, setting-up Java 3D should probably fix the issue but I'd like to just deliver/setup Java 3D together with/in a subfolder to simbad-1.4.jar IOW to not install Java 3D into a standard C:\Program Files (x86)\Java\Java3D location.
Please advise how can I setup Java 3D packaged together with simbad-1.4.jar, or answer a more general question:
How to deploy a Java client application, which uses Java 3D, packaged together with Java 3D library?
P.S. I know about and I have used -classpath option to successfully run other sample java client apps' .jar(s) I have made exported by using Eclipse but they haven't used nor Java 3D nor simbad-1.4.

I'm using a slightly different environment (Win7-64bit, JDK 1.7), but this should work for your environment also.
download java3d .zip package from https://java3d.java.net/binary-builds.html
unzip the downloaded file, and there's is another zip file named "j3d-jre.zip"
unzip 'j3d-jre.zip' in a directory you want to package together.
place simbad jar file in that directory.
create a DOS batch file with these lines in it:
#echo off
set CLASSPATH=.;.\lib\ext\j3dcore.jar;.\lib\ext\j3dutils.jar;.\lib\ext\vecmath.jar;.\simbad-1.4.jar
set PATH=%PATH%;.\bin
java -classpath %CLASSPATH% simbad.gui.Simbad
Hope this helps.

Related

Install4J - hide .jar file from installation directory?

I am currently working on turning my java application into a windows installer, converting the .jar into and .exe file.
Have chosen Install4J because of the ability to bundle JDK with the application, as well as recognizing previous installations when deploying updates.
Only problem I have, is the fact that the jar file for the application, is saved in the installation directory as well.
Does anyone know how to fix this? I don't want the original jar file in the directory, just the converted exe file.
The .exe file is just a launcher for the JVM, it does not contain natively compiled Java code.
The best way to protect your code is to use an obfuscator like ProGuard.

install4j: Force a launcher (EXE) to use DLLs from bundled JRE folder

We use install4j 8.0.8 in our application. Since a new release of the application we use JRE 11.0.10 from Azul and found out that small amount of users under Windows 10 were unable to load the application with exception: java.lang.UnsatisfiedLinkError: C:\Users\user\AppData\Local\thinkorswim\jre\bin\awt.dll: Can't find dependent libraries. We were unable to reproduce the issue on our machines.
We've found in Internet some similar issues with other applications and it was said there could be a broken Windows installation (may be some DLLs were corrupted). Many pages contain mentioning of msvcp140.dll.
With Windows Resource Monitor we found out that our application (started with install4j native EXE launcher) loads msvcp140.dll from c:\windows\system32, but JRE 11 contains the DLL inside bin folder. Then we ran our application without the native launcher (just java -jar) and Resource Monitor showed that msvcp140.dll has been loaded from jre\bin folder.
We've asked a user to repeat and they said that the application can be launched with java -jar.
I've played with PATH environment variable and java.library.path via a .vmoptions file and I was unable to force the launcher to use DLLs from the bundled JRE.
Is it possible to tune the native launcher to make it load DLLs from the JRE bin folder?
On Windows, executables always try to load DLLs from their directory first. That is why java.exe will load DLL dependencies from the bin directory before looking in the system32 directory,
The install4j launcher does not call java.exe, but starts the JVM via JNI so it's not the bin directory of the JRE but the directory of the launcher that is looked at first. Unfortunately, it is not possible to change this behavior.

Install4j - embedding jar into generated launcher

I have 'generated launcher' which executes my java application - aplication is in jar package.
Is there any way how to include jar into generated EXE file(launcher)? Customer wants to have only exe file, not jar in installed folder. Is there any way how to do it?
There is no way to do that with install4j. You can do it with exe4j, by using the "JAR in EXE" mode and add the generated executable to the distribution tree instead of using the generated launcher. This only works for Windows, though.

JNA finds library running in Eclipse but not when a built JAR file

I am writing a program which needs to use a .dll file. When my program starts up, the following code is executed:
public static void main(String[] args)
{
String dLLURL = "C:/Program Files (x86)/Location of DLL";
System.setProperty("jna.library.path", dLLURL);
System.setProperty("jna.debug_load", "true");
System.setProperty("jna.debug_load.jna", "true");
Application.launch(args);
}
I then execute
DllInterface dllinterface = (DllInterface) Native.loadLibrary( "dllName.dll", DllInterface.class);
...which loads the correct dll and allows me to use it. JNA outputs the following (this time using the actual name/path of the DLL):
Trying (via loadLibrary) jnidispatch
Looking in classpath from sun.misc.Launcher$AppClassLoader#e2f2a for /com/sun/jna/win32-x86/jnidispatch.dll
Found library resource at jar:file:/C:/Users/bengs_000/Downloads/jna.jar!/com/sun/jna/win32-x86/jnidispatch.dll
Trying C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna2314341730536889248.dll
Found jnidispatch at C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna2314341730536889248.dll
Looking for library 'RailDriver.dll'
Adding paths from jna.library.path: C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins
Trying C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
Found library 'RailDriver.dll' at C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
This is what happens when I run the program in Eclipse IDE. It works just fine!
However, when I build/run the program as a .jar, the application says the DLL cannot be found (despite looking in the correct location) and returns the following message:
Trying (via loadLibrary) jnidispatch
Looking in classpath from java.net.URLClassLoader#677327b6 for /com/sun/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:rsrc:jna.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Trying C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna8530559464473818762.dll
Found jnidispatch at C:\Users\BENGS_~1\AppData\Local\Temp\jna-792348840\jna8530559464473818762.dll
Looking for library 'RailDriver.dll'
Adding paths from jna.library.path: C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins
Trying C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
Adding system paths: []
Trying C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\plugins\RailDriver.dll
Looking for lib- prefix
Trying libRailDriver.dll
Looking in classpath from java.net.URLClassLoader#677327b6 for RailDriver.dll
There was an error finding your raildriver.dll file
As you can see, exactly the same path is taken to find the .dll file yet it works in Eclipse and not as a compiled .jar file!
Would you please be able to help me identify the problem? One thing to note is that the .dll file is stored within the 32bit section of Program Files, and my computer is 64bit. I am using Java 32bit to compile and run the program in Eclipse. Surely it should build the .jar with Java 32bit right?
I have found a solution!
The Background
I knew that the problem was related to the .dll I wanted to use being 32bit, and my computer being 64bit. In the Eclipse IDE, I was running the app using Java 32bit (I knew I should to this to ensure compatibility).
When running the .jar file, Java was defaulting to the 64bit version; different to how I was testing it in Eclipse.
The Solution
To force the user to use Java 32bit, you need to bundle the .jar into an .exe file. I used Launch4J to do this. There's a parameter in Launch4j which allows you to specify which systems of Java to use. This is located under the JRE tab in the "Search Options" section. By changing it to "32-bit only", the .jar file is launched under Java 32-bit, thus alleviating the problem!
I hope this might help some one!

Leap Motion Java SDK, java.library.path

I'm using LeapJava.jar to write a simple JDK program to interface with the Leap. I've roughly followed this article: Developing for the Leap Motion controller in Scala and in theory it's all very simple. However, when I try to run the program it fails with a RuntimeException when it tries to connect to the Leap device:
Native code library failed to load.
java.lang.UnsatisfiedLinkError: no LeapJava in java.library.path
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
I've followed the steps in the Leap documentation but since I'm using Ubuntu (and sbt) there aren't clear instructions that relate directly to this situation. I've tried various different parameters for the java.library.path argument:
pointing at the ./lib dir in the project (which contains LeapJava.jar)
using the Leap SDK's lib directory
absolute path to the Leap SDK's lib directory
the x86 dir within the LeapSDK's lib directory
symlinking the LeapJava.jar file into the x86 directory and using that
I get the same problem running it in IntelliJ (set up as described in the Leap docs linked above) or from the command line. e.g.
sbt -Djava.library.path=.:/<path to LeapSDK>/lib run
I've added the LeapJava.jar to the classpath in sbt (it's in the lib directory) and the project compiles fine.
Any advice (particularly as I'm on Linux, which is poorly documented) would be most welcome.
Copy the .dll files in the the project(your current working directory) folder since it looks for the native libraries in that particular folder.
From the Readme in the Leap Motion Linux package:
Q. ...Sample.java compiles, but when
attempting to run, I get an error about unable to load
libLeapJava.so
A. Java seems to have trouble searching for native
libraries without some guidance. Try:
LD_LIBRARY_PATH=. java -classpath .:LeapJava.jar Sample
which looks like it assumes the jar file and native libraries are in the same folder as your application.
I got things rolling in eclipse on Ubuntu by doing the following.
1)Select your project in the Package Explorer area and press a right click on it.
2) Select Build Path → Configure Build Path... option.
3) In the appearing window, select the Libraries tab.
4) Then, expand the JRE System library option and select the Native library location.
5) Click on the Edit button at the right panel
6) click external folder.
7) navigate to your download of the sdk .../LeapSDK/lib/x64
if you are on a 32 bit system use x86
You should now be able to use LeapJava.jar without error.