I have this code in Java that I'm to compile and execute. The code itself is working and the compilation goes ok. When I execute the code giving the classpath, with a command like "java -cp classes:lib/* main.class parameters" it works well.
But the problem is when I try to generate a jarfile and execute it with a command like "java -jar file.jar parameters". When I execute this, code starts running but crashes on the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy<br>
at java.lang.ClassLoader.defineClass1(Native Method)<br>
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)<br>
at [...]
Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.TrustStrategy<br>
at [...]
... 17 more
I thought it could be missing some class on MANIFEST, though for what I could find on the internet, the package providing this class is httpcore, which is included there. I tried to modify in many ways the manifest with no success, so I don't believe the problem is on this file.
I don't know if it helps, but the code is being compiled with ant and I have some 3rd-party libs stored on a lib folder, which is on the classpath of MANIFEST.
I'm compiling on a computer with:
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
And running it on a computer with:
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-1ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
Does anyone know why may this be happening?
Related
I am trying to use Princeton Course specific Java Compiler (javac-algs4) on my windows machine and am seeing this error:
$ javac-algs4
warning: [path] bad path element "/usr/local/lift/lib/algs4.jar": no such file or directory
javac: no source files
This is related to Princeton Algorithms 1 Course. I followed the instructions on installing IntelliJ Idea from https://lift.cs.princeton.edu/java/windows/ and other steps to configure CLASSPATH.
javac and java work ok on HelloWorld programs, but I am expecting javac-algs4 to work for programs that use Course specific libraries.
It seems to me like a Unix Path may be hidden in the JAR file that I`m using in the CLASSPATH, and that may be breaking things for me. (Notice the /usr/local... directory in my error)
What steps could I take to troubleshoot and resolve the error?
Other Version Info:
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Javac Version: javac 10.0.2
I have trouble when trying to open my jar files with the following command:
java -jar software.jar
They load until a certain point and then nothing happens.
I deinstalled default-jdk and OpenJDK with synaptic and re-installed it with apt-get, but nothing changed. I had a similar problem one month ago and solved it (apparently only temporarly) by deleting the package gcj-5-jre-lib (5.4.0-6ubuntu1~16.04.4) (Java runtime library for use with gcj (jar files))
The following outputs will help:
java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
javac -version
1.8.0_131
My variables $JAVA_HOME and $JRE_HOME were correctly added to my $PATH.
I'm on Ubuntu 16.04
EDIT
Here is an example of what I get when I try to start PhyDE.jar
java -jar PhyDE.jar
Welcome to PhyDE 0.9971!
Reading preferences.
Creating PhyDE-Application window
Checking for updates...
You are using the latest version of PhyDE
Done with checking for updates
When checking the core use with the command top I see that the process is active, but the user interface does not open as it usually does. I am located in the folder where the jar file is, and same happens with other jar files.
I built and ran a JAR on machineA as follows:
java -cp /foo/lib/dep1.jar:/foo/lib/dep2.jar:/foo/export/myjar.jar foo.bar.baz.MyMainClass ...
So myjar.jar is the JAR I built and the other two its dependencies. Ran without any issues.
I then wanted to do the same on machineB so I copied the 3 JAR files there, then tried:
/non/default/install/java -cp /bar/dep1.jar:/bar/dep2.jar:/bar/myjar.jar foo.bar.baz.MyMainClass ...
and got Error: Could not find or load main class. (NOTE: /non/default/install/java is a separate java install on machineB that I have to use instead of /usr/bin/java. Reason is "historical", i.e. I have no control over this)
On machineA, java -version gives
java version "1.7.0_91"
OpenJDK Runtime Environment (rhel-2.6.2.2.el6_7-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
On machineB, /non/default/install/java -version gives
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
Both machines are running RedHat 6.
Why am I getting the error and how do I fix it?
Thx!
IMPORTANT UPDATE: I ran the commands below from command line on machineA. On machineB I originally ran them using a bash script. This means that I put them into run.bash and then ran bash run.bash from the command line. That's when I got the error. When I reran the same command from command line without using any scripts, it worked. So it seems that the problem had nothing to do with me copying the JAR form one machine to another but rather with the fact that I was invoking them form a script. And so the question really is now: how do I modify run.bash and/or the way I execute it to get rid of the error? (cuz I do need to use a script eventually)
So I downloaded JNativeHook 1.1.4 from
Link for JNativeHook
And then I added it to my build path and compiled the program. I tested the program on my Linux VPS and get this error.
[root#nl ~]# java -jar file.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/tmp/libJNativeHook_468389387164048348.so: libXt.so.6: cannot open shared object file: No such file or directory
The program was compiled using Java 1.6 and my VPS is running.
[root#nl ~]# java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (rhel-2.5.1.2.el6_5-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
How can I get my program to work on Linux?. The program is working fine on Windows.
When i run yum whatprovides '*/libXp.so.6 I get this.
libXp-1.0.0-15.1.el6.x86_64 : X.Org X11 libXp runtime library
Repo : base
Matched from:
Filename : /usr/lib64/libXp.so.6
I have a program i've written and turned into a jar file. The jar file works just fine on my computer. When I try to run the program on the server it will be running on, the jar file doesn't work. I get this error.
Exception in thread "main" java.lang.NoClassDefFoundError: Publish
Caused by: java.lang.ClassNotFoundException: Publish
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Publish. Program will exit.
I think this problem is caused by different versions of java or different environments or something. I think the libraries are not the problem here, but the environments where this program is being run. The jar file works perfectly on my own computer.
My java version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
Server java version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
I also get this error, which suggests that I may have a 32 bit java while the server has a 64 bit and this might be causing problem.
Error occurred during initialization of VM
Could not reserve enough space for object heap
I got around this error easily by just allocating some memory to running this process.
Does anyone have any idea about how to fix this problem?
Note: i also looked at the manifest file and it seems fine
You are using Publish without the package. This means java expects this class in default package.
You need to use the fully qualified name, for instance: foo.bar.Publish
From documentation:
By default, the first non-option argument is the name of the class to
be invoked. A fully-qualified class name should be used. If the -jar
option is specified, the first non-option argume nt is the name of a
JAR archive containing class and resource f iles for the application,
with the startup class indicated by the Main-Class manifest header.
You need to include the full package name. This error is not that of 32/64 bit OS's, or differences in Java Environments.