I tried to run DependencyParserDemo.java in Stanford NLP parser.
I use Win7, jdk-10.0.1.
In command line:
Javac -cp stanford-parser.jar DependencyParserDemo.java
Works fine, DependencyParserDemo.class generated.
But when I run:
Java -cp stanford-parser.jar DependencyParserDemo
It shows:
Error: Could not find or load mian class DependencyParserDemo
Caused by: java.lang.ClassNotFoundException: DependencyParserDemo
Maybe the classpath setting is wrong?
You also need the location of the new class in your classpath.
Java -cp stanford-parser.jar;. DependencyParserDemo
Related
Almost everywhere in INTERNET there are these basic steps:
• Compile java files as usual
javac <source-files>
• “Instrument” the byte code
java -jar jcov.jar Instr <application classes>
• Run the code
java -classpath ...:jcov_file_saver.jar ...
• Create a report
java -jar jcov.jar RepGen <jcov xml file> demo
I was able to instrument class files and jar files both, but couldn't run jar one.
Faced this error:
$ java -cp .:$JCOV/jcov_file_saver.jar -jar BubbleSort.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tdk/jcov/runtime/Collect
at BubbleSort.main(BubbleSort.java:49)
Caused by: java.lang.ClassNotFoundException: com.sun.tdk.jcov.runtime.Collect
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
)
Can anyone please help me out or direct me to some web-page where I can understand this?
You also need to provide the jcov.jar file as well because it contains the com/sun/tdk/jcov/runtime/Collect class.
To supply the jcov.jar at run time, run this
java -cp .:$JCOV/jcov_file_saver.jar -Xbootclasspath/a:$JCOV/jcov.jar -jar BubbleSort.jar
Using this resolved the issue faced thanks to sumedh's answer which pushed me to understand about various kind of classpaths.
Executing instrumented jar:
java -cp . -Xbootclasspath/a:$JCOV/jcov_file_saver.jar -jar BubbleSort.jar
I'm new to Java and have a program that's throwing the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
at ExtractCustomerIds.main(ExtractCustomerIds.java:21)
Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base#9-internal/BuiltinClassLoader.java:366)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base#9-internal/ClassLoaders.java:184)
at java.lang.ClassLoader.loadClass(java.base#9-internal/ClassLoader.java:419)
... 1 more
I know the problem has to be with paths, classpath or jar name, but I can't figure out as of now.
My folder structure is:
.
- get_customer_ids
- ExtractCustomerIds.java
- libs
- jackson-all-1.9.11.jar
So when I'm inside the get_customer_ids I give the following command:
get_customer_ids$ javac -cp ../libs/* ExtractCustomerIds.java and this causes the error above.
I thought I was setting the classpath correctly, but it's still not working. What's missing?
The exception occurs when running your program - you are specifying the classpath while compiling. The classpath set during compilation is not stored inside the compiled class files or the like - you need to correctly specify it when running your program, too!
Like so:
$ java -cp ../libs/* ExtractCustomerIds
running a java class by shell script:
java -cp $CLASSPATH CG_GpsRequest "dbname","oracle.jdbc.driver.OracleDriver","abc","abc"
while running the script in unix, getting error,
Exception in thread "main" java.lang.NoClassDefFoundError: CG_GpsRequest
Caused by: java.lang.ClassNotFoundException:
CG_GpsRequest is the class file name.
Okay.. If I understand you correctly..
I think its problem with the Package name specification..
Your calss CG_GpsRequest you must have specified in Packaging way for example
com.xxx.yyy.CG_GpsRequest
So I think JVM is searching your class com.xxx.yyy.CG_GpsRequest in this patter so Please run your script with the following modifications.
java -cp $CLASSPATH com.xxx.yyy.CG_GpsRequest "dbname","oracle.jdbc.driver.OracleDriver","abc","abc"
This is just assumption that you have created your class in Pacakgin hirarechy since you havent specified more information.
Add the folder/path in which your java class exists to your CLASSPATH
java.lang.NoClassDefFoundError
I have a java program which is dependant on two jar files.
i compile the program using command :
javac -classpath jar1.jar:jar2.jar myprog.java and it compiles successfully.
But when i try to run the program using command : java -cp jar1.jar:jar2.jar myprog , it is throwing the java.lang.NoClassDefFoundError . please help , where am i wrong ?
i am using ubuntu 10.04.
Actual error :
Exception in thread "main" java.lang.NoClassDefFoundError: userapps/SelectionTask_classes/SelectionTask
Caused by: java.lang.ClassNotFoundException: userapps.SelectionTask_classes.SelectionTask
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: userapps/SelectionTask_classes/SelectionTask. Program will exit.
where SelectionTask is my class file generated after successful compilation.
Make sure that the current directory is also in the classpath. Try running with:
java -cp .:jar1.jar:jar2.jar myprog
if your compiled class file myprog.class is in the current directory.
(This assumes that your program is not in a package).
You need to add directory where your compiled java program (*.class) file is located. If it's in current directory then you could run it like this (notice "." which denotes current working directory):
java -cp .:jar1.jar:jar2.jar myprog
Look at the error, it's complaining about not being able to find "userapps.SelectionTask_classes.SelectionTask", which hints at the last entry in your classpath not beign specified correctly. Now, assuming that the JAR files you have specified are in the following directory structure:
./hadoop-0.20.1-core.jar
./lib/hadoopdb.jar
./userapps/SelectionTask_classes/
You would run:
java -cp hadoop-0.20.1-core.jar:lib/hadoopdb.jar:userapps/SelectionTask_classes/ myprog
I am new to jython. Here is my failed attempt to use javac to complie my python script into class file.
rohit#rohit-laptop:~/backyard$ echo "print 'hi'" > test.py
rohit#rohit-laptop:~/backyard$ jython test.py
hi
rohit#rohit-laptop:~/backyard$ jythonc test.py
Warning: jythonc is unmaintained and will not be included in Jython-2.3. See http://jython.org/Project/jythonc.html for alternatives to jythonc. Add '-i' to your invocation of jythonc to turn off this warning
processing test
Required packages:
Creating adapters:
Creating .java files:
test module
Compiling .java to .class...
Compiling with args: ['/usr/bin/javac', '-classpath', '/usr/share/java/jython.jar:/usr/share/java/servlet-api-2.4.jar:/usr/share/java/libreadline-java.jar:./jpywork::/usr/share/jython/Tools/jythonc:/usr/share/jython/Lib:/usr/lib/site-python:__classpath__', './jpywork/test.java']
0
rohit#rohit-laptop:~/backyard$
rohit#rohit-laptop:~/backyard$ cd jpywork/
rohit#rohit-laptop:~/backyard/jpywork$ ls
test.class test.java test$_PyInner.class
rohit#rohit-laptop:~/backyard/jpywork$ java test
Exception in thread "main" java.lang.NoClassDefFoundError: org/python/core/PyObject
Caused by: java.lang.ClassNotFoundException: org.python.core.PyObject
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: test. Program will exit.
rohit#rohit-laptop:~/backyard/jpywork$
Please suggest the correct way.
Jython will automatically compile it into .class file on first execution, however in case you want to compile it, you can use standard library, find py_compile.py or compileall.py on Jython lib folder.
$ java test # is not the exact command to execute the class file
this class file requires jython.jar file to execute you have to give the jython.jar path at the run time.
#java -cp /home/litindia/jython-2.0.1/jython.jar:. test
-cp is compulsory /home/litindia/jython-2.0.1/jython.jar is my path where is jython.jar is present in my system, your path may be different. so please give the appropriate path.
And after the path :. is compulsory. Then file name is required.