Programs works on my pc, but not server - java

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.

Related

JDK for Ghidra give me Error: "Could not find or load main class LaunchSupport"

I downloaded JDK 15 for my windows 10 64 bit pc and put the environment variable JAVA-HOME correct and the PATH also. This give me in cmd:
C:\Users\patpin>java -version
java version "15.0.2" 2021-01-19
Java(TM) SE Runtime Environment (build 15.0.2+7-27)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)
When I start Ghidra (even as admin) I get:
Error: Could not find or load main class LaunchSupport
Caused by: java.lang.ClassNotFoundException: LaunchSupport
Error: Could not find or load main class LaunchSupport
Caused by: java.lang.ClassNotFoundException: LaunchSupport
Error: Could not find or load main class LaunchSupport
Caused by: java.lang.ClassNotFoundException: LaunchSupport
Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section.
Maybe this issue can be solved by updating the lunch.properties file.
First, try to fullfil their minimal requirements. According to ghidra's documentation
Current Ghidra 9.2.2 need Java 11 64-bit Runtime and Development Kit (JDK)
So, it is better to install java 11 64 bit.
If ghidra fails to locate the jdk, then force it by-
To launch with a specific version of Java, set the JAVA_HOME_OVERRIDE property in the support/launch.properties file. If this property is set to an incompatible version of Java, Ghidra will revert to automatically locating a compatible version.
This may be because you're using the release from github, and these releases are not built and only contain the source code.
Source: https://github.com/NationalSecurityAgency/ghidra/issues/2872
To fix the issue, you can try download ghidra from here https://www.ghidra-sre.org/

ClassNotFoundException when executing a .jar, but not when executing with classpath

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?

UnsupportedClassVersionError when starting Cassandra 2.0.6

I'm fully aware that this question has already been asked in a way in this thread:
Cassandra:UnsupportedClassVersionError
However, the answer/s given there, which I accept, don't solve my problem as I do have a current version of Java as detailed below:
D:\Development\Cassandra\apache-cassandra-2.0.6>java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Client VM (build 24.45-b08, mixed mode, sharing)
Knowing this, I still receive the error when starting Cassandra:
D:\Development\Cassandra\apache-cassandra-2.0.6>bin\cassandra -f
Starting Cassandra Server
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/cassandra/service/CassandraDaemon : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.apache.cassandra.service.CassandraDaemon. Program will exit.
I'm running on a Windows XP machine using the command prompt (not Cygwin) to start Cassandra and I'm able to start older versions of Cassandra without any issue (apache-cassandra-1.1.4). Am I doing something incorrect with the later version of Cassandra or have I missed something somewhere in my configuration that is blindingly obvious?
The only plausible explanation for that exception is that a Java 6 (or earlier) JVM is being use to run code that was compiled for the Java 7 target platform.
This contradicts what you believe to be happening. Nevertheless, it is the only plausible explanation.
I suggest that you make a copy of the cassandra wrapper script (in the same directory), and hack it to:
add set -x at the start to see what commands are actually being run by the script.
add echo $PATH, echo $JAVA_HOME and so on to see what the key environment variables are in the script's environment.
add a line to run java -version using the exact same command path that is being use to run the JVM for real.
This should reveal which of your beliefs / assumptions about what is happening are incorrect.
I did try with uninstalling java 1.7 and installing the latest java 8 got solved my issue.

Netbeans not reading .jnilib file

I have a project on netbeans that I am trying to run on my mac. The problem is every time it gets to the line:
System.load(libPath + File.separatorChar + "libjdic.jnilib");
It gives me the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: {path}/libjdic.jnilib: no suitable image found. Did find: {path}/libjdic.jnilib: no matching architecture in universal wrapper
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1020)
at ------.-------App.main(--------App.java:113)
Java Result: 1
I have checked, and the paths are all correct. This is working on windows, but I need it to work on mac as well. It is properly determining the OS and deciding which additional files to load (In this case .jnilib). I have seen a similar question on here, but without an answer.
SPECS:
Mac OSX 10.8.4
64bit
Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)
Netbeans version 7.3.1
Does anyone know why this is happening?

Weka ClassNotFoundException

I'm attempting to install Weka, which I have installed into /weka directory. I set the CLASSPATH variable, but that shouldn't matter anyway because I'm using -cp.
I enter this into SSH:
java -Xmx5G -cp /weka/weka.jar
weka.core.converters.TextDirectoryLoader -dir /home/myuser/test >
/home/myuser/test.arff
And it spits out:
Exception in thread "main" java.lang.NoClassDefFoundError:
weka/core/converters/TextDirectoryLoader Caused by:
java.lang.ClassNotFoundException:
weka.core.converters.TextDirectoryLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: weka.core.converters.TextDirectoryLoader.
Program will exit.
What wrong? There is no "weka/core/converters/TextDirectoryLoader" because its all stored in weka.jar, which is where it should be looking.
My Java version:
java version "1.6.0_20" OpenJDK Runtime Environment (IcedTea6 1.9.10)
(rhel-1.23.1.9.10.el5_7-x86_64) OpenJDK 64-Bit Server VM (build
19.0-b09, mixed mode)
I just downloaded Weka today from the link on their downloads page, so there shouldn't be anything wrong with it.
Now I know that this would normally be because it can't find weka.jar, but I promise you that it is right there at: /weka/weka.jar. And I can also promise that both the /weka directory and weka.jar have execute permissions.
Please help!
Just downloading and running the .jar works for me:
carsten#dallas:~$ java -Xmx5G -cp /tmp/weka-3-6-5/weka.jar weka.core.converters.TextDirectoryLoader
Usage:
TextDirectoryLoader [options]
Options:
...
as well as java -jar /tmp/weka-3-6-5/weka.jar, which opens some GUI tool.
You sure that you installed Weka on the server you SSH into?
I happened the same to me in Mac OS when I used the jar released in the dmg packaged.
Instead of that one, I imported the jar file under:
Applications/Weka/Resources/java/weka.jar
To get it you have to:
go to Applications
right click over weka-3-x-x
Show package content
go to /Resources/java/weka.jar
import that one jar into your classpath

Categories