I have a jar file of my application.
When i run it using java -cp "jarfile.jar" com.my.MainClass it works just fine but if i give it to other devs, there is a clear case where i get this error:
Error: Could not find or load main class com.my.MainClass
Caused by: java.lang.ClassNotFoundException: com.my.MainClass
It is as such, only not working on Mac's. (Windows is fine)
Mac java version:
openjdk version “11.0.2” 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
Windows java version:
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
I do not have any sun.* dependencies. Only finding dependencies under java.util, java.net, java.io, java.nioorg.junit (which is bundled in jar).
Will gladly give more info if necessary, just have no idea what is missing as such.
can you try this and ensure that you must be in parent folder of com directory
from your question MainClass is in following package hierarchy com->my->MainClass.java
and your class file MainClass.class also will present in same package hierarchy.
while running this MainClass you must be in parent directory of your com folder and try the following command for compile or run
in windows:-
for compile (ensure that you executing this command in parent folder for com directory)
javac -cp "jarfile.jar;." com\my\MainClass.java
java -cp "jarfile.jar;." com.my.MainClass
for Mac or linux (ensure that you executing this command in parent folder for com directory)
javac -cp "jarfile.jar:." com/my/MainClass.java
java -cp "jarfile.jar:." com.my.MainClass
Related
I am trying to install wso2ei-6.4.0, but it will not run due to the following error messages. I am running a RPi with Debian
Error: JAVA_HOME is not defined correctly.
CARBON cannot execute java
I have executed Java -verison and have the following return
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)
I know the java directory, using Java -which
/usr/bin/java
How do I run Java from any of the directory to execute the installation of wso2ei-6.4.0?
After some time and reading, I managed to add the following into ~/.bashrc:
export JAVA_HOME="/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt"
export PATH=$PATH:$JAVA_HOME/bin
Note the arm32 directory for the jdk
Try this (as root user):
export JAVA_HOME=/usr/bin/java
Does this solve your issue?
I am using Mac os Sierra 10.12.3 ,I want to execute the byte code on the Java(TM) Virtual Machine
(JVM) I need to set the CLASSPATH,
Using my terminal
CLASSPATH=</Users/.../Documents/jj2000/jj2000-4.1\ 3>/jj2000-4.1.jar:$CLASSPATH export CLASSPATH
show me
-bash: /jj2000-4.1.jar:: Permission denied
I am confusing with command line how can I set the CLASSPATH.
My java is
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b20)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b20, mixed mode)
Please help.
Don't, ever, set a global CLASSPATH environment variable. Pass the classpath to each java program you launch: each one has its own, specific classpath.
java -cp /path/to/jj2000-4.1.jar:your-application.jar com.yourcompany.youapp.Main
When I try to run apache gora compiler using ./gora goracompiler, I m getting the following error
Error: Could not find or load main class org.apache.gora.compiler.cli.GoraCompilerCLI
Before that I got JAVA_HOME not set error after that I resolved that error by setting JAVA_HOME variable
OS: Cent OS 6.5
Java version : java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
goracompiler command expects GoraCompilerCLI to be in $GORA_HOME/gora-compiler-cli/target/classes/
Check you have gora-compiler-cli/target/classes/java/org/apache/gora/compiler/cli/GoraCompilerCLI.class or the .jar from the module gora-compiler-cli in the classpath.
If not, compile the module with:
mvn package -pl gora-compiler-cli
I setup Java 6 to be used by all other application. Normal setup with JAVA_HOME, JRE_HOME, etc. This is working fine.
I have another application that needs Java 7. I downloaded Java 7.exe and extraced tools.zip from it to a folder. Now I am trying to check the version going to the bin folder. When I type in java -version, I get the following error.
error occurred during initialization of vm
java/lang/noclassdeffounderror java/lang/object
where as java -fullversion shows Java 7. It looks like even though I am in the bin folder where Java.exe exists, it still getting the one from PATH?!?!
How do I use the java.exe from a folder ignoring the one from PATH?
You need much more than java to run java. You need all the rt.jar and lib which come with Java. It sounds like you are missing some part of the JRE or it can't find your JRE.
I suggest you re-install the version you need and run it using the full path name like
c:\>"c:\Program Files\Java\jdk1.7.0_60\bin\java" -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
c:\>"c:\Program Files\Java\jdk1.8.0_45\bin\java" -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
By using the full path name you can use any specific version from any directory.
i am new to java & Linux, i have a problem regarding setting PATH in kali linux to run Java Programs, i have set the path as shown below after that i have executed the basic commands of java like java-version, javac, but when it comes to compile a java program it is showing the error as:& also why it is showing lower version of java, though even i have installed latest version of Java i.e JDK1.8.0_31, TIA
root#kali:~# PATH=/home/opt/jdk1.8.0_31/bin:$PATH
root#kali:~# export PATH
root#kali:~# java -version
java version "1.6.0_33"
OpenJDK Runtime Environment (IcedTea6 1.13.5) (6b33-1.13.5-2~deb7u1)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
root#kali:~# javac
root#kali:~# javac Hello.java
javac: file not found: Hello.java
It is well set. The error message is exactly what is happening. The file is not there.