I am trying to run a Java executable through the command line.
First I go to the directory the executable is located at and execute the following:
java -cp .;JARNAME-0.0.1-SNAPSHOT.jar main.class.name
This is a packaged jar so it does not have any .class files.
However, this command sporadically throws the Error: Could not find or load main class main.class.package.name error message.
Does anyone have any suggestions to get to the bottom of this?
Thanks
Last argument is class name, not package name
Related
I have created a .jar of my image processing project which runs on intellij idea.While running .jar using java -jar project.jar it outputs an error Error: Could not find or load main class sample.Main. But when i extract the .jar and go to the inside and open the terminal and then run java sample.Main [sample is the package] , it works perfectly. I think problem may be the class path. How can i solve this.
I need some help with a really trivial problem which i cannot get to work. So i create a simple java project with two files. RectangleApplication.java and AreaCalculator.java (in the same src folder). Then I compile them with javac *.java. Then i create a jar file for AreaCalculator.class and removes the AreaCalculator.class from the src folder. If i now execute
"java Main", i will get a ClassNotFoundException which i was expecting. What i was not expecting was to get a "could not find or load main class RectangleApplication when i ran the command
java -cp .:area-calculator.jar RectangleApplication
Can someone please explain to me what i am doing wrong. I have tried everything, but when i add a runtime classpath to find my jar, it will not find my Main class.
I am new to Java and JNA. I was trying to access the native interfaces of a third party applications using JNA from Java eclipse. So I was trying to set the jna.library.path from Command line using the command
java -Djna.library.path=<path to your library> MainClass
I have given the "path to your library" as the path of the folder where my .dll file and its dependencies are there. for ex: D:Adrin\Library\Dll.
"MainClass" I have given the name of the class with main() in my application(Jnaexe.java). But an error occurs saying
Error: Could not find or load main class Jnaexe.java
I have also tried by giving the package name and also the whole path of the Jnaexe.java. Still it does't work. I tried running from the src folder and even the folder where Jnaexe.java file is there(example folder) in command prompt. But the error was same.What I am missing here. Any help will be highly appreciated. Thank you in advance
I'm trying to run a class that I wrote that is importing the jawin library.
My command line is as below:
java -cp C:\class_path ClassName
I'm getting:
Exception in thread 'main' java.lang.NoClassDefFoundError org/jawin/funcptr
What am I doing wrong?
Doesn't the JAR that I'm adding to the build path get into the binary file that I've compiled?
If not, then when I publish my class file how will it know to find the external JAR? What if it doesn't exist on the target computer?
I have a simple file system, in which all the files being used by the main program are in the same folder. The main program is also in the same system. It was actually a jar file by my friend and then I unzipped it using winrar, the class files are running well, but only when i amended something and tried to compile the program i am getting this error of cannot find symbol for one of the class being used, and its right there in the same folder. How can i resolve this please?
Thanks in advance
You have to place your source files into appropriate subfolders. The name of the folder corresponds to your package name, in this case next.
next/Pretty.java
next/Tree.java
...
Then you can compile using command
javac next/*.java
from the base directory.