Having trouble running Java program with Command Prompt - java

I'm getting the error Error: Could not find or load main class ExcelFileEditor when trying to run my program. I compiled the program with no errors by:
javac -cp C:\Users\rperera\IdeaProjects\LinkingNames\libs\*;. C:\Users\rperera\IdeaProjects\LinkingNames\src\ExcelFileEditor.java
I tried doing:
java ExcelFileEditor
java -cp C:\Users\rperera\IdeaProjects\LinkingNames\libs\* ExcelFileEditor
but I keep getting the same error. I'd really appreciate it if someone could help me fix this problem!
public static void main(String[] args) {
//this allows the Py4J module in Python to use whichever methods it needs from this class
ExcelFileEditor editor = new ExcelFileEditor(new File(args[0]));
GatewayServer server = new GatewayServer(editor);
server.start();
}
The package is excel.writer

If you are not specifying where to place the generated class files then its going to be in the same directory as the source file.
Try
java -classpath C:\Users\rperera\IdeaProjects\LinkingNames\libs\*;C:\Users\rperera\IdeaProjects\Li‌​nkingNames\src excel.writer.ExcelFileEditor

Related

How to run a java class on ubuntu?

If I compile and run the program. I don't have any issues.
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
If I add the line package ch01.sec01; it complies correctly with javac. However when I try to run it using java I get:
Error: Could not find or load main class HelloWorld
I have tried the following.
export CLASSPATH=/usr/lib/jvm/java-9-openjdk-amd64/bin:/usr/lib/jvm/java-1.9.0-openjdk-amd64/bin
That is why when you use a package in your code, that path must be the actual path of your java file (That means that your code is supposed to be in a directory called sec01 which is inside directory ch01).
With that being set, when running code inside a package, you need to include the path in the command. To do so, after you have compiled your code with javac, navigate to the root of the path (outside ch01 directory) and type
java ch01.sec01.HelloWorld
This should work.

Java - Could not find or load main class Class01

Using Java 8
I have set my PATH as 'C:\Program Files\Java\jdk1.8.0_144\bin'
I also tried to set my CLASSPATH as 'C:\Program Files\Java\jre1.8.0_144\lib\rt.jar', though I read it is not neccesary.
From Class01.java I have no problem creating Class01.class
javac Class01.java -> created Class01.class
Still, when I try to run program
java Class01
I got message
Error: Could not find or load main class Class01
If anyone know, how to fix this, I appreciate every hint.
Btw. My program does nothing but printing Hello world, if it has something to do with my problem.
You will need to tell Java about the classpath where it should find your file. I think you are missing the classpath parameter in your java command (see below). Here is a simple example how you could create a java file, compile and run it:
A. Create File:
public class X {
public static void main(String[] args) {
System.out.println("Blah!");
}
}
B. Compile:
"%JAVA_HOME%\bin\javac" X.java
C. Run it using the `-classpath` parameter:
"%JAVA_HOME%\bin\java" -classpath . X
This will print out:
Blah!
Note that JAVA_HOME is a System variable in Windows which needs to point to the location of your Java Runtime Environment.

Could not load main method when setting class path

I am trying to run a java program in linux server which includes an imported jar.
While compiling it is not giving any issues , but when I try to run, it is giving an error "Error: Could not find or load main class ". If I remove the import and its references , my code is working fine without any load issues.
Any inputs please
javac -cp "/opt/CARKaim/sdk/pwdsdk.jar" SamplePwd.java //No issues
java -cp "/opt/CARKaim/sdk/pwdsdk.jar" SamplePwd //Error: Could not find or load main class
Assuming SamplePwd has an entry-point (e.g. main(String[] args)) make sure the current folder is also in your class-path, like
java -cp "/opt/CARKaim/sdk/pwdsdk.jar:." SamplePwd

Cannot load native library. Error: java.lang.UnsatisfiedLinkError

I am having trouble getting Java to see the file 'libvensim.so' that I have in my home directory.
I have tried setting LD_LIBRARY PATH...."echo $LD_LIBRARY_PATH" returns "./libvensim.so"
When I run the code:
java -cp ./vensim.jar:. -Djava.library.path=./libvensim.so Test
I get the error "Cannot load native library. Error: java.lang.UnsatisfiedLinkError: no libvensim in java.library.path".
Test.java is a simple class to test whether I can access the .so:
import com.vensim.Vensim;
public class Test {
public static void main(String[] args) throws Exception {
Vensim vensim = new Vensim("libvensim");
}
}
Can anyone see my problem? Thanks very much.
LD_LIBRARY_PATH should point to the directory containing the .so files. Try:
java -cp ./vensim.jar:. -Djava.library.path=. Test
or
export LD_LIBRARY_PATH=/path/to/dir
java -cp ./vensim.jar:. Test

Unable to run HelloWorld from command line

OK, I just cannot get java to run my .class files:
I follow steps in Oracle tutorial and try to run this program:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
Compiling OK:
PS C:\Users\Ztaz> javac .\HelloWorldApp.java
But after I try to run it, I get this:
PS C:\Users\Ztaz> java .\HelloWorldApp.class
Error: Could not find or load main class .\HelloWorldApp.class
no exception, nothing.
Here's my PATH variable, if it helps (split into lines, for readability):
%JBOSS_HOME%;
%SYSTEMROOT%;
%M2%;
%JAVA_HOME%\bin;
...
JAVA_HOME is set to "C:\Program Files\Java\jdk1.7.0". My question sounds a lot like this one but I had this problem on Java SE 6 as well, so I decided to post separate question.
Run it without the .class: java HelloWorldApp
This causes issues for lots of people starting out with Java. Not sure why Java doesn't just look for both files (the name provided and the name with .class appended).

Categories

Resources