Command: java -jar [...] Fails with Error Message - java

I am running java 1.8.0_65 on Windows 7.
I create a JAR and run it with the following command:
java -jar printxml.jar
And get this error:
Error: Could not find or load main class printxml.PrintXml
Here is my command to create the JAR:
jar cmfev manifest.txt printxml.jar printxml.PrintXml #filelist.txt
Contents of file "manifest.txt":
Class-Path: C:\Users\Me\SQLSER~1\JDBC\jtds-1.3.1.jar
I checked whether printxml.PrintXml class is in the JAR via this command:
jar tvf printxml.jar printxml/PrintXml.class
The command succeeded, i.e. PrintXml class is in the JAR.
I then checked if the PrintXml class in the JAR has a "main" method via this command:
javap -classpath printxml.jar -public printxml.PrintXml
The command succeeded and its output included...
public static void main(java.lang.String[]);
Searching the Internet, I found only the obvious answers, like:
Your classpath is wrong.
Your class doesn't have a "main" method.
Can someone please tell me how to resolve this problem?
Thanks,
Avi.

As Homer Simpson would say: D'OH
The value of the Class-Path entry in file "manifest.txt" is wrong!
It needs to be a URL!
So I changed it to:
file:/C:/Users/Me/SQLSER~1/JDBC/jtds-1.3.1.jar
Hey presto! No more error message. Now it runs!
Thanks to all who helped. ;-)

Related

Encountered error when I try to run a class: Exception in thread "main" java.lang.NoClassDefFoundError. JAR

I am a new beginner of Java. I wrote a Hello.java file with a extend jar package "algs4.jar"(my textbook asked me to use their own output/input library(Algorithm 4th Edition)), which can print a 'Hello,World!\n' string on the shell when executed.
It was compiled without any error, (command:javac -cp E:\AlgorithmExercise\lib\algs4.jar E:\AlgorithmExercise\codes\Hello\Hello.java)
but when I tried to run the class (command: java codes.Hello.Hello), I got this error.
I guessed the reason of this error is because I forgot to enter the path of the algs4.jar package. so I modified the command: java -cp .;E:\AlgorithmExercise\lib\algs4.jar codes.Hello.Hello, but the terminal informed me that it "cannot find or load the main class."
I am absolutely cannot understand what's going on, my classpath has no mistake on configure.

Could not find or load main class

I want to run a java project in terminal. When I compiled, no error occurred, but when I run the program I get the following error:
Could not find or load main class orException in thread "main"
java.lang.NoClassDefFoundError: Appium (wrong name:
com/appiumproj/test/Appium)
Please help me to solve this problem.
iMac:~ Samuel$ javac -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar: /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/Appium.java
iMac:~ Samuel$ java -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar: /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/Appium
Error: Could not find or load main class .Users.Samuel.Downloads.AppiumTest.src.com.appiumproj.test.Appium
iMac:~ Samuel$
You need to specify the name of the class - not a filename. It needs to be the fully-qualified class name, and it needs to be on the classpath. So after compiling, you'd want something like this (just spread out on multiple lines for readability; the backslashes are line continuations - you should be able to copy and paste this straight into your shell):
java -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar\
:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar\
:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar\
:/Users/Samuel/Downloads/AppiumTest/src \
com.appiumproj.test.Appium
Are you sure your compiled version is in /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/ ? I would say that it is probably where the javac was run. Check and find it and specify the path to to compile version

Error in executing a jar file

I have a jar file named- ParseCSV-0.0.1-SNAPSHOT.jar and the contents of it are -
META-INF/
META-INF/MANIFEST.MF
foo/
foo/ReadCSV.class
META-INF/maven/
META-INF/maven/Test/
META-INF/maven/Test/ParseCSV/
META-INF/maven/Test/ParseCSV/pom.xml
META-INF/maven/Test/ParseCSV/pom.properties
The main class is ReadCSV.class and it takes a CSV file (C:\Testting\ValidaResults.csv) as an input parameter. I am trying to execute the jar file from the command promt by running the following command-
java -jar . ParseCSV-0.0.1-SNAPSHOT.jar "C:\Testting\ValidationResult.csv"
But I am getting an error saying-
Error: Could not find or load main class foo.ReadCSVTest
What is going wrong here.
Why do you have a . between jar and ParseCSV..?
Try this first:
java -jar ParseCSV-0.0.1-SNAPSHOT.jar "C:\Testting\ValidationResult.csv"
If this does not work, then try:
java -cp ParseCSV-0.0.1-SNAPSHOT.jar;. foo.ReadCSV "c:\Testting\ValidationResult.csv"
If this works, then i would inspect the META-INF/MANIFEST.MF file to figure out what the classpath is like, and what the value of Main-Class is. It seems to be running ReadCSVTest instead of ReadCSV.
Your JAR file includes foo/ReadCSV.class, but your MainClass is set to foo.ReadCSVTest. You'll need to fix your Main-Class attribute in META-INF/MAINIFEST.MF

Error importing jar in groovy script (soapui)

I have a problem with running java code from groovy script (groovy script is a part of SoapUI test suite)
i create simple script:
import myjar.jar
new TopClass().sayHello()
the code of TopClass:
public class TopClass {
public void sayHello (){
System.out.println("Hello");
}
}
I put myjar.jar into both soapui-pro-2.5\lib and soapui-pro-2.5\bin\ext folders.
But running script I get:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed, Script1.groovy: 2: unable to resolve class myjar.jar #
line 2, column 1.org.codehaus.groovy.syntax.SyntaxException: unable to
resolve class myjar.jar # line 2, column 1. at
org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:113)
at
org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:970)
at
org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at
org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:527)
at
org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:772)
at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:438)
at
groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:281)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:572) at
groovy.lang.GroovyShell.parse(GroovyShell.java:584) at
groovy.lang.GroovyShell.parse(GroovyShell.java:564) at
groovy.lang.GroovyShell.parse(GroovyShell.java:603) at
Please help me to find what I'm doing wrong
Putting the jar under soapui-pro-2.5\bin\ext is all you need for the classes to be found (although restarting SoapUI won't hurt).
However - you should check that the error you get is related to your jar. Is com.my.research available within myjar.jar? If no - just add it.
If yes, add more detailed information to your post.
import myjar.jar
I believe this is not correct, you should be importing the name of the java package not the name of the jar.
Hope this helps
On non-windows implementations of soapui I find it helps if you add it to the .sh file that starts soapui explicitly.

cannot run JOCL samples downloaded from jocl.org. (OPENCL for java)

I have downloaded the sample file from jocl.org and compiled it without problems (c:\javac -cp c:\jocl.jar JOCLSample.java)
When I tried to run it (c:\java -cp c:\jocl.jar JOCLSample), some errors occurred:
C:\Users\Ruoyu>java -cp C:\j.jar JOCLSample
Error: Could not find or load main class JOCLSample
How do I correct this?
If JOCLSample.class is in C:\Users\Ruoyu, change your -cp parameter to C:\j.jar;C:\Users\Ruoyu

Categories

Resources