Running java using cmd following commands but getting error
java -cp %etc_folder%%service%%library%
i did set up environment variable for etc_folder, service, library
library envi: target\service_service-05.2015.jar
I check the folder jar file is in folder.
getting following error:
Exception in thread "main" java.lang.NoClassDefFoundError: target\service_service-05/2015/jar;
caused by: java.lang.ClassNotFoundException: target\service_service-05.2015.jar;
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I think it's replacing "." to "/"
not sure why, can anyone please help with this.
Thank in advanced!!
You should execute Java as following pattern:
java -cp $(echo /opt/path/lib/*.jar| tr ' ' ':') com.xxx.xxx.MainClass
All your jar putting into /opt/path/lib/,
com.xxx.xxx.MainClass is which class you have main() function.
Related
I wrote some Java code that takes several arguments using Eclipse. I was able to compile and execute the code just fine by entering the arguments in the "Run configurations."
However, I need to be able to run my code via command-line. This is what I tried:
javac -g ./MyCode.java
java MyCode ./fileOne.txt ./fileTwo.txt ./fileThree.txt
And the error message:
Exception in thread "main" java.lang.NoClassDefFoundError: mypackage/MyCode
Caused by: java.lang.ClassNotFoundException: mypackage.MyCode
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I don't understand what is going on. My code does not have any bugs when I run through Eclipse. Help?
You are not setting up the classpath properly.
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
I'm a newbie in running Java code in Linux environment. I'm trying to get the Astyanax to work on the linux machine.
I followed the instruction on https://github.com/Netflix/astyanax/wiki/Getting-Started
I have cloned the code from github, and ./gradlew build runs successfully.
I'm trying to run the AstClient in the astyanax-examples. I tried the following command:
java -cp "/home/shbash6/astyanax/astyanax-examples/build/libs/;/home/shbash6/astyanax/astyanax-cassandra/build/libs/;/home/shbash6/astyanax/astyanax-core/build/libs/;/home/shbash6/astyanax/astyanax-thrift/build/libs/" com.netflix.astyanax.examples.AstClient
under holder:
/home/shbash6/astyanax/astyanax-examples/build/classes/main
but I got the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/netflix/astyanax/examples/AstClient
Caused by: java.lang.ClassNotFoundException: com.netflix.astyanax.examples.AstClient
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.netflix.astyanax.examples.AstClient. Program will exit.
Could anyone tell me how to fix this issue? Thanks!
Use : classpath separators on *nix platforms
java -cp "/home/shbash6/astyanax/astyanax-examples/build/libs/*:/home/shbash6/astyanax/astyanax-cassandra/build/libs/*:/home/shbash6/astyanax/astyanax-core/build/libs/*:/home/shbash6/astyanax/astyanax-thrift/build/libs/*" com.netflix.astyanax.examples.AstClient
I am trying to command line compile my code and I cannot get it to run properly. My project was in eclipse and I could specify the location of a jar file to include but the command line is another issue. All .java and the .jar file are in the same director.
I can compile with
javac -classpath opencsv-2.3.jar *.java
I get the following exception if I try to run my code.
java ClassificationGenerator
Exception in thread "main" java.lang.NoClassDefFoundError: au/com/bytecode/opencsv/CSVReader
I tried running the code with
java -classpath opencsv-2.3.jar ClassificationGenerator
but then I get
Exception in thread "main" java.lang.NoClassDefFoundError: ClassificationGenerator
Caused by: java.lang.ClassNotFoundException: ClassificationGenerator
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
You need to give the jar in the classpath while running, aw well:
java -classpath .;opencsv-2.3.jar ClassificationGenerator
To compile my java app, I use from terminal:
javac -cp commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar CollectionIndexer.java
To run the app I use:
java -classpath commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar CollectionIndexer
However I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: commons-digester-2/1/commons-digester-2/1/jar:lucene-core-3/0/3/jar
Caused by: java.lang.ClassNotFoundException: commons-digester-2.1.commons-digester-2.1.jar:lucene-core-3.0.3.jar
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)
I guess I'm defining correctly the classpath.. or what ?
Try -cp instead of classpath. Also add the current directory to the classpath.
$ java -cp .:commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar CollectionIndexer
or
$ export CLASSPATH=.:commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar
$ java CollectionIndexer
If on Windows, use backslashes and a semi-colon separator:
java -cp .;commons-digester-2.1\commons-digester-2.1.jar;lucene-core-3.0.3.jar CollectionIndexer
I would suggest you to set the classpath first with
SET CLASSPATH command and then execute your program as
java CollectionIndexer.
The title pretty much says it all, I am trying to get a java program (.jar file) to run from a Perl program. I read another post on Stackoverflow saying this syntax is correct:
system("java filename.jar");
However this is giving me the following error. I'm not sure if the problem is that it shows the filename as "filename/jar" instead of "filename.jar"
Exception in thread "main" java.lang.NoClassDefFoundError: filename/jar
Caused by: java.lang.ClassNotFoundException: filename.jar
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)
You need to call it as java -jar filename.jar.
If you leave out the -jar, then java thinks you're trying to run a class named filename.jar, which it tries to load from the filename/jar file. Since you don't have that file, java throws the error that you see.
You have to use the -jar option to launch a jar.
java [ options ] -jar file.jar [ argument ... ]
Resources :
sun.com - java