I'm trying to make a jar that the user can double-click to run (not a .exe just a jar that can be double-clicked). The problem is while this question has been asked many times none of the answers have worked.
I think the problem is not on my system, because other jar files on my system (that I didn't create) run fine. This makes me suspect I am doing something wrong.
First I tried this example.
However when I tried running the jar I made with that solution with:
java -jar HelloWorld.jar
I got the error: "no main manifest attribute in HelloWorld.jar"
I suspect the error is with my manifest file so here is is:
Manifest-Version: 1.0
Main-Class: main.Main
I also tried: "File --> Export --> RunnableJar" in eclipse but while that allowed me run to my jar from the command line when I tried double-clicking it I got the following message: "A Java Exception has occurred".
At this point, I don't know what to do to make my jar double-clickable.
What can I do to make my jar double-clickable?
Update: I used a new command:
jar cfe HelloWorld.jar main main.class
Now when I try to run this new jar from the command line with
java -jar HelloWorld.jar
I get the following error: "Could not find or load main class main"
If you did everything as described in that example, I think that there is no association with the *.jar file in the registry. Check it.
Also it maybe that two versions of Java installed.
Check Right-Click -> Open With. Java Runtime should be listed there.
Related
I need to make an executable jar for my ending project and I keep getting the "Could not find main class"....
I've tried with export > runnable jar and export > jar file (and I did chose the main) in both cases I get the same error.
Details in the runnable:
My run configurations for the main of the project:
The dependencies in my project:
I'm totally lost and i don't know where's the problem
Verify that you can start your application like that:
java -cp myjarfile.jar Principal.java
You're double-clicking the file on a windows explorer window? Try to run it from a console/terminal with the command
java -jar myjarfile.jar
Please check below link for further clarification . Running JAR file on Windows
I'm having big problems running my java api war file from the command line after ive packaged it with maven.
I'm trying to run it using the following command from the target folder where my war file is located.
java -cp silverkissen.war se/consys/silverkissen/heroku/Main
And alot of other variations but i just get
Error: Can't find or load main class se/consys/silverkissen/heroku/Main
My war file lies in path ..\Silverkissen-API\target\silverkissen.war
My heroku main class lies in path ..\Silverkissen-API\target\classes\se\consys\silverkissen\heroku\Main.class
Thankful for any help.
The main issue is most likely because the class files isn't incorporated into the silverkissen.war file. Meaning there is no Main function in the war file itself. Or that the entry function is some where else.
Or that it's packaged in some mysterious way that is beyond my understanding that's specific to maven, heroku etc.
But assuming you're standing in the project root structure, one level before the target folder usually where you'd normally have src, target, pom.xml and system.properties. I'd try running the following:
java -cp target/classes:target/dependency/* se.consys.silverkissen.heroku.Main
And if you're on Windows that'd be:
java -cp target\classes;target\dependency\* se.consys.silverkissen.heroku.Main
That aught to do it. This will execute your project with class-path's in the runtime. Assuming my limited knowledge of Java is correct.
Someone with more experience can probably explain in detail why this would work.
Open command prompt in the location where your jar/war located
And then run below command
java -jar silverkissen.war
I have been doing a coding exercise inside the IntelliJ IDEA Community Edition 14 IDE, using OpenJDK.
The project is split over 4 .java files all in the same package.
My end goal is to run this in the terminal/bash (I use System.console().readLine() which doesnt play nicely in the IDE's console).
I've tried navigating to the directory where these 4 files reside (they all reside in the same dir) and tried:
javac -classpath . BibliotecaApp.java Book.java BookManager.java LibraryDB.java
This creates 4 corresponding .class files fine.
The Main is in bibliotecaApp.java/class, so I try run it by:
java BibliotecaApp
But I get the error
Exception in thread "main" java.lang.NoClassDefFoundError: BibliotecaApp (wrong name: com/twu/biblioteca/BibliotecaApp)
Plus about 13 lines of specifics.
Now googling this error seems to be a class path problem, and this is where I get stuck.
From places I've read, usingecho $PATH gives me:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
This is still from the directory of the .java files above.
That path means nothing to me. I have no idea what it is or what it does, or what even a classpath is! Theres alot of resources out there on setting a classpath, but they aren’t helping me because I don't know what it's meant for.
That was a dead end for me. I tried to create a .jar instead using IDEA's Build Artifacts as seen HERE. It created a .jar file but when I navigate to that directory and try run it via:
java -jar biblioteca_jar
I get
Error: Invalid or corrupt jarfile biblioteca_jar
Another issue is that in the file explorer, the file actually comes out as biblioteca.jar, but ls on that dir shows biblioteca_jar. Is that normal?
The code is on my GitHub if that helps anything
https://github.com/botagar/twu-biblioteca-JohnGeddes
Based on your compiler step, change this
java BibliotecaApp
to
java -cp . BibliotecaApp
Which will add the current directory to the classpath for the java runtime environment. See also the Oracle Technote Setting the Class Path.
A jar file is a kind of zip, and should have a .jar extension. So this
java -jar biblioteca_jar
should probably be
java -jar biblioteca.jar
And you can check if the file is valid with any zip archive reader. Including jar itself,
jar tvvf biblioteca.jar
Edit
Based on your comments below,
cd ~/Documents/ThoughtWorks Uni/TWU_Biblioteca-master/src/
and then
java -cp . com.twu.biblioteca.BibliotecaApp
I'm trying to make a jar file out of two classes, one of which depends on an external jar. I have a directory with a manifest.txt, a lib folder containing the external jar RXTXcomm.jar, and a folder named Arduino containing my two classes, SendValue.java and SerialClass.java.
First I'm compiling my classes using:
javac arduino\*.java
This creates 3 new files, SerialClass$1.class, SerialClass.class and SendValue.class. To make the jar file, I'm running:
jar -cfm send.jar manifest.txt arduino\*.class lib\rxtxcomm.jar
This works fine. I then try to run the file using:
java send.jar
I get the error:
Could not find or load main class send.jar
I've also tried to run it with the following command, and got the same error:
java -cp . send.jar
The only line in my manifest.txt is :
Main-Class: Arduino.SendValue
My classes run fine in Eclipse, so I'm assuming they're not the problem. SendValue.java has the line:
public static void main(String[] ag) {
as it's supposed to.
Any ideas?
You want to run your jar using:
java -jar send.jar
Also, unless you want to do some magic with nested jars with some tool like OneJar, you should remove lib\rxtxcomm.jar from your jar command, and add the following line to your manifest.
Class-Path: lib\rxtxcomm.jar .
If you're going to use the command line or terminal for running a single java executable, then use
java -jar send.jar
Also it would be better if you went through compiling and testing using an IDE such as Netbeans, IntelliJ IDEA, or Eclipse as they're meant to do such stuff and are more reliable on doing the steps unlike the human brain.
I have exported a jar file that I want to run the console. The code compiles and runs correctly in eclipse but I am having an issue running it from the console.
To me it looks like the referenced jar's I added via built path in the Eclipse project file and not being added to the export. If that is the case, how do I ensure that they do? If not, what am I doing wrong?
When you export your source code's class files to a jar using eclipse, only the .class files of your source are exported! Hence your exported jar file doesn't contain the referenced jars you mentioned in eclipse! Due to this, the error occurs while executing from command prompt.
Solution:
Take all the jar files required to execute the program, store it in the same directory as you store the exported jar file. Now while executing the java command, provide all the jar file's names in classpath field as following:
java -classpath .;JAR1.jar;JAR2.jar MainClass
Once you do this, your problem should be resolved!
The dependencies need to be on the classpath, i.e. run like this:
java -cp <path_to_jar1>;<path_to_jar2> -jar ScrumTimeCaptureMaintenence.jar
When running from the command line make sure any dependencies are set on the class path by listing them in the -classpath parameter