I have a simple java project (adapted from the example here), which is as follows:
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.BranchGroup;
public class HelloWorld {
public HelloWorld()
{
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) {
System.out.println("Hello World!");
System.out.println("PATH : " + System.getProperty("java.library.path"));
new HelloWorld();
}
}
My output is:
Hello World!
PATH : /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib
Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:200)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:157)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:987)
at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:299)
at HelloWorld.<init>(HelloWorld.java:10)
at HelloWorld.main(HelloWorld.java:20)
I assume this Exception indicates that the library libj3dcore-ogl.so could not be found. Here's where it is located:
$ locate libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so
As the output above shows, /usr/lib/jni is inside java.library.path. What am I doing wrong? (I'm using Ubuntu 10.04 and Eclipse 3.7.2 - if that may be an issue?)
Java is a bit of unknown territory for me. So please be as verbose as possible on your notes/suggestions/answers.
Update 1
Apparantly it's a 64-bit library (on a 64-bit operating system):
$ file /usr/lib/jni/libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
I use openjdk as runtime environment. Both java3d (libjava3d-java) and the openjdk (openjdk-6-jdk) is installed via aptitude.
Interestingly, it works if I compile and run the application from my terminal:
javac -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld.java
java -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld
But I would really like to use eclipse to do this kind of things.
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
It also works with Eclipse, if I copy the native library (libj3dcore-ogl.so) to the jvm directory and add the libraries (j3dcore.jar, j3dutils.jar, vecmath-1.5.2.jar) as external jars to the build path libraries (right click on project -> Properties -> Java Build Path -> Libraries -> Add External JARs...):
sudo cp /usr/lib/jni/libj3dcore-ogl.so /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/
But I wonder if there really is no solution that wouldn't require this copy.
I went through similar issues while trying to run a foreign project requiring java3d. I'm using Eclipse only for the compilation and packaging runnable jar parts (as it is a Maven project), but the runtime errors I was getting were of the same kind. And I want to confirm that moooeeeep's answer was pertinent and very helpful. The reason why I'm posting here is mainly because I think this can be useful for other people to give the full steps (independently from Eclipse, since setting up things using Eclipse facilities or Maven dependency ones failed, in both cases). Everything here is all about setting up correctly the JRE.
Note: I'm working under OpenJDK-7-amd64 (and Debian - 64 bit system). So feel free to adapt the following steps for i386 if applicable (just replace "amd64" by "i386").
Here's what worked for me then :
sudo apt-get install libjava3d-jni libjava3d-java libvecmath-java
This will add required files to be injected in the JRE:
$ locate j3d
/usr/lib/jni/libj3dcore-ogl.so
/usr/share/java/j3dcore-1.5.2+dfsg.jar
/usr/share/java/j3dcore.jar
/usr/share/java/j3dutils-1.5.2+dfsg.jar
/usr/share/java/j3dutils.jar
Since those files are located in different places but definitely not in the JRE's ones, copy (or link) as follows:
Dynamic libraries :
sudo cp /usr/lib/jni/libj3dcore-ogl.so /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/
JARs :
sudo cp /usr/share/java/j3d*.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
sudo cp /usr/share/java/vecmath-*.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
Resulting in :
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/libj3dcore-ogl.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dcore-1.5.2+dfsg.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dcore.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dutils-1.5.2+dfsg.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dutils.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/vecmath-1.5.2.jar
Hope this can be of any help...
I had the same issue on anothe project, this solved it for me:
Open the run configuration of your project, select the "Arguments" tab and insert the following into the "VM arguments" box
-Djava.library.path=/usr/lib/jni
I don't know why you have to give the path here again. It also doesn't work with relative ones, but this way it works for me.
java.lang.UnsatisfiedLinkError is thrown only if the definition of a native method can't be found.
Related
I am going through Tiny OS tutorial lesson number 4 "Mote-PC serial communication and SerialForwarder" and I am stuck on the line where it says
"Once you have installed TestSerial, you need to run the corresponding Java application that communicates with it over the serial port. This is built when you build the TinyOS application. From in the application directory, type
$ java TestSerial
However when I type this, I face the following error
Error: Could not find or load main class TestSerial
I tried several things to fix this issue, but none helped.
Solutions that I tried:
set CLASSPATH to the directory that I am currently in, which is
export CLASSPATH=.:/home/wsn/tinyos-main/apps/tests/TestSerial
2)set CLASSPATH to the directory where tinyos.jar is located
export CLASSPATH=.:/home/wsn/tinyos-main/support/sdk/java/tinyos.jar
3)run command using java -cp . TestSerial
however I keep having the same error
Is there any other better way to fix it?
I am using Virtual Machine with Fedora OS
I am trying to run the program on mib520 platform and I use iris motes
my java version
openjdk version "1.8.0_31"
OpenJDK Runtime Environment (build 1.8.0_31-b13)
OpenJDK Server VM (build 25.31-b07, mixed mode)
You must have skipped the step when you had to run the make command.
Navigate to the apps/tests/TestSerial folder and type make [platform] (such as make telosb, make iris e.t.c), the makefile that will be run will be the makefile in the TestSerial folder which is defined as follows:
COMPONENT=TestSerialAppC
TOSMAKE_PRE_EXE_DEPS += TestSerial.class
TOSMAKE_CLEAN_EXTRA = *.class TestSerialMsg.java
TestSerial.class: $(wildcard *.java) TestSerialMsg.java
javac -target 1.4 -source 1.4 *.java
TestSerialMsg.java:
nescc-mig java $(CFLAGS) -java-classname=TestSerialMsg TestSerial.h test_serial_msg -o $#
TINYOS_ROOT_DIR?=../../..
include $(TINYOS_ROOT_DIR)/Makefile.include
So the makefile compiles TestSerial.java. After this you can proceed to installing the application and then running the TestSerial application.
So step by step on a iris mote for example you would
Navigate to the apps/tests/TestSerial Folder
Make the application by typing make iris
Connect your mote and then type motelist. This command will list all connected motes. The name of your mote should be listed under the "Device" section. Note this for use in the next two steps.
Install your application by typing the command make iris install.1 bsl, [DEVICE NAME]. This will make and upload your program to your device.
Run the TestSerial application by running java TestSerial -comm serial#[DEVICE NAME]:iris
If you use another platform such as telosb then just replace all occurances of iris in the commands above with telosb.
I need to uninstall Java jdk1.6.0.27 from RHEL 5.7 and then install another version jre-7u40-linux-x64.rpm.
The firs thing I did was to find out the current java version installed using the
java -version command and the output is "java version "1.6.0_27"".
After that I tried to check the previews version of java with the command:
rpm -qi jdk
The output is "package jdk is not installed"
After installing the package jre-7u40-linux-x64.rpm in the /usr/java directory there are two java packages.
The output of the ls command on /usr/java is:
default jdk1.6.0_27 jre1.7.0_40 jre-7u40-linux-x64.rpm latest.
when I run the command "alternatives --config java" the output is:
*+ 1 /usr/java/latest/bin/java
I am new to RHEL and I need some help to understand the situation.
To conclude I need some help to remove the previews jdk1.6.0.27 and to install jre1.7.0_40.
Thank you in advance for your help!
Best regards,
Claudio
First, find out your real java executable. Start with
which java
This is going to give you some response such as:
/usr/bin/java
Next, do
ls -l /usr/bin/java
(Or whatever it returned).
It will probably write something like:
/usr/bin/java -> /etc/alternatives/java
Do the same for whatever is pointed to by the arrow, until finally, when you do ls -l on it, there is no arrow.
Then, for that particular file, find out which rpm provides it by using
rpm -q -f <full path of the file you found>
It should tell you which package it belongs to, and then you can uninstall that.
However, if the rpm command returns The file ... is not owned by..., then your Java has not been installed using an rpm. It may have been installed manually by someone in the past.
This makes uninstalling it a lot more problematic.
If you haven't found your answer:
leave old java where it is, don't even bother with it
install new version with: rpm -ivh /root/jdk-7u40-linux-x64.rpm
deactivate old java
export new version
Deactivating old java (note entering hashtags before every line, manual installation required editing of profile, so edit it one more):
vi /etc/profile
#JAVA_HOME=/usr/java/jdk1.6.0_27
#export JAVA_HOME
#PATH=$JAVA_HOME/bin:$PATH
#export PATH
Exporting nev version (note adding new lines in profile followed after old entries):
export JAVA_HOME=/usr/java/latest
export JRE_HOME=$JAVA_HOME/jre
export J2RE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$J2RE_HOME/bin:$PATH
Check nev version with standard command for checking of installed sw.
Hope this suits your needs.
Just wondering: you're trying to prepare BFBOX for acceptance? Just courious! If you want more info please send me an email, ok?
I've written a Java program that uses OpenCV library. So far, I executed the program with eclipse (and set the Jar location in eclipse properties).
This is a college final project. My instructor now wants to run the program in his computer. How can I generate a runnable jar(using Ant or using Java code) that will load the Java OpenCV jar from specific location (a directory that will be located in the executable Jar directory), that will work with Linux and Windows (I understood that linux uses a Jar file, and Windows uses a dll file)?
I've tried using:
String currentDir = System.getProperty("user.dir");
System.load(currentDir + "/path_to_jar/opencv-248.jar");
(let's ignore the fact that it will only work with linux) But when executing the jar, the following error occurs:
OpenJDK 64-Bit Server VM warning: You have loaded library /path_to_jar/opencv-248.jar which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c ', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /path_to_jar/opencv-248.jar: /path_to_jar/opencv-248.jar: invalid ELF header (Possible cause: endianness mismatch)
Any help would be highly appreciated.
Use the classpath option for your java executable.
If you're running OpenJDK read the manpage at http://linux.die.net/man/1/java-java-1.6.0-openjdk
You should be able to use something along the lines of:
java -jar yourapp.jar -cp ./path_to_jar/
Another option is to build a JAR which includes its own dependencies. Here are some examples I found using the search terms "java create jar include dependencies":
Using Maven
Using Eclipse
I have a java program in which a use the GLPK Solver. The error that i receive when i run it on eclipse is the following:
The dynamic link library for GLPK for Java could not beloaded.
Consider using
java -Djava.library.path=
The current value of system property java.library.path is:
/Users/maria/Documents/solver_library/GLPK/w64
I had the same problem on my old windows computer and i solved it doing the following:
1. Adding in the Java Build Path->Libraries the glpk-java.jar file
2.Adding as the Native library location of the above jar the corresponding path (C:\ProgramFiles\solver_library\GLPK\w64
3. adding in the PATH environment variable the above path.
I am doing exactly the same things on my new MAC OS X computer but still receiving the above error. I did with exactly the same way the steps 1 and 2 above and also I modified through the terminal the PATH system variable. This now is:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/maria/Documents/solver_library/GLPK/w64
Could you please tell me if you have any idea of how to solve this? I am a new Mac user so i don't know many things.
Thanks in advance!
Here's what I did to make it work on OS X.
Install glpk.
I used for this homebrew
$ brew install glpk
$ brew install swig // this package we well need for glpk for java
Install glpk for java http://sourceforge.net/projects/glpk-java/files/glpk-java/
Unzip the archive with:
$tar -xzf glpk-java-1.0.37.tar.gz
$cd glpk-java-1.0.37
Configure with:
$./configure \
CPPFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers \
SWIGFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers
Make and install with:
$make
$make check
$make install
Now in swig dir you should have 3 jars:
glpk-java.jar, glpk-java-sources.jar, glpk-java-javadoc.jar and the .lib folder (hidden).
For compiling you need to put glpk-java.jar in your classpath and specify javac option -Djava.library.path=/YOUR_PATH/libglpk-java-1.0.37/swig/.libs
I have installed Java 1.7.0_45 on Mac OS X 10.6.8 using Pacifist [http://www.charlessoft.com/] however I am unable to run a jar file which I have downloaded. The jar file is a threaded application.
The error message I am getting is:
java -jar context.jar
2013-10-31 14:14:41.898 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement methodSignatureForSelector: -- trouble ahead
2013-10-31 14:14:41.900 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement doesNotRecognizeSelector: -- abort
Trace/BPT trap
Is there anyway I can run the jar. I have set the JAVA_HOME path properly and java -version is showing 1.7.0_45 as the version.
The same application works properly on Windows Java 1.7.0_45 and also on Linux Java 1.7.
The web search for the solution and the given keywords return very few results and none of them have any specific solution in it. I am new to mac so I am not fully able to understand the issue.
Alternatively, is there anyway I can run Java from folder in Mac like I can do in windows and Linux by just extracting the Java contents and changing the JAVA_HOME. If that is possible then I should be able to run my JAR.
I had kind of same problem while installing an application through jar file, my Java was not detected by the jar application installer,
Over here I see that one of the method is not accessible, could be a same problem. But I am not very sure of it.
make sure you have rt.jar in your JAVA_HOME/jre/lib/ folder
In case you don't have then you are required to have it through the process of creation of symbolic link.
In the command below replace your_java_version with proper version matching your requirement.
sudo mkdir -p /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib
Go into the directory:
cd /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib/
Create symbolic link :
sudo ln -s ../../../Classes/classes.jar rt.jar
Hope this solves your problem.
I get the exact same problem with MacOS 10.6.8 and JDK 7. In order to run the jar I had to use the System JRE which is 1.6.x (In my case I wanted to install Squirrel
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar >squirrel-sql-3.6-MACOSX-install.jar