Alrighty, so I packaged my files into an executable .jar using Eclipse, however when I try to run it by clicking or opening it informs that it "could not find or load main class Calculator.jar".
However, if I launch it from the command prompt, (java -jar Calculator.jar), it runs like a charm. What's the issue here?
maybe you can try this: Jarfix
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 have compiled my jar file using jar cmf manifest.mf SysInfo.jar *.class and got no errors, but when I try to execute the file by clicking on it nothing happens. I don't even get an error pop up. But when I run the jar using the console it will execute perfectly.
What can I do to make the file run by clicking it?
Try starting it via console using
java -jar yourFile.jar
Don't forget to cd in the directory your .jar file is located before you do this.
EDIT: Sorry, you already said it works like that. Try right click open with.. and then choose open with javaw.exe
If that also doens't work you need to provide more information.
I am trying to create a JAR file for my code. I have tried it with both NetBeans and IntelliJ, on both Windows and Linux. In all cases, it gives me an error; Could not Find or Load Main Class.
Using NetBeans, I simply pressed Build for the project and the jar file was generated. I tried checking for the main manually (Right Click -> Properties -> Run) but it was set well already. It was set right packageName.Main. Also, I do have a public static void main(String[] args) method. The method compiles and works in the console, but when it comes to creating the Jar file, I get this error.
I have tried running the jar file using java -cp Name.jar Name, java Name.jar Name and a bunch of other commands, all to no avail.
Any ideas?
Thanks in advance.
EDIT: Although it works using cmd, I can't open the program when double clicking on the .jar file. Any ideas?
Done. Compile with java -jar Name.jar command. Thanks to mtaschuk
I wrote a simple game with 2D graphics in Java (Eclipse) and lib Slick2D. When I export project to Runnable Jar File in Eclipse and try to run this file just nothing happens. I can run this game in Eclipse without any problems. When I write java and put my jar in console to get path and hit enter i have sth like that:
C:\Users\Me>java C:\Users\Jolanta\Desktop\pnd.jar Error: Could not
find or load main class C:\Users\Jolanta\Desktop\pnd.jar
In launch configuration while exporting I selected right main class. Any ideas?
it's command for starting jar file with main class:
java -jar C:\Users\Jolanta\Desktop\pnd.jar
You need to provide native libraries along with the jar file. Here are some scripts that will launch your game:
windows (.bat file) :
java -Djava.library.path="native/windows/" -jar pnd.jar
linux :
java -Djava.library.path="native/linux/" -jar pnd.jar
where your directory will look like this:
your .jar and scripts are in the same directory along with 'native' folder.
not sure where I got this folder from, I can send it to you if you want
I have created a Java JAR file in NetBeans. I have already run clean and build on the program and everything was successful. When I run the program in NetBeans is also successful, but when i locate the JAR file in the NetBeans dist folder and run it, nothing happens. The program doesn't run, and there are no exceptions or messages. Could you please help me understand why.
EDIT: I already solved the problem.
It sounds like you're probably on Windows :)
One way to "run" a .jar file is to create a Windows File association for ".jar" suffix and the "javaw.exe" command:
1) Go into Windows Explorer and [Browse...] to your .jar file
2) Right-click the .jar file, and select the "open with..." option.
3) Select javaw.exe as above, and see if it runs.
Are you trying to make executable jar ? You might wanna put your main class in manifest of the jar file.
Something like :
Main-Class : file_name_with_main_method
I would suggest checking the Console if you are on a Mac. You can view errors from the Jar launch to understand why it failed.