I went to eclipse>export>java>runnable jar file
I changed launch configuration to my project name; destination: desktop.
I tried all three library handling options:
extract required folders into generated JAR
Package required libraries into generated JAR
copy required files into a sub-folder next to the generated JAR.
I did not check anything to do with "ANT scripts".
When I pressed "finish" in the export window, eclipse gave me a error: "Could not find main method from given launch configuration". After pressing the "finish" button in the eclipse export window, the next button was grayed out. It created a JAR file at the destination. When I tried to open it Mac's Jar Launcher (default)(13.5.0), it gave me the message:
The Java JAR file "filename.jar" could not be launched.
Check the Console for possible error messages.
I googled this and some people said to check the manifest.mf file. I extracted it, then: "META-INF>manifest.mf". I opened manifest.mf with textedit.
Inside manifest.mf were the lines:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ acm.jar
Class-Path: .
I am running Mac OSx 10.6.8 snow leopard. I have the latest java available for snow leopard (I think my java is the one just BEFORE java 7).
Also, I'm trying to export a project with:
a .java file that contains all my code
acm.jar
java.policy.applet
Scores.txt
My .java file contains a public void run() {} and JFrames/JPanels. My .java file extends ConsoleProgram.
If there's no public static void main(String[] args) method, the virtual machine (Java) will not know where to start your program. It sounds like your run() method is what you want to start your program. If so, then add (to your main class (.java)) a method: public static void main(String[] args). Re-export your .jar, making sure the launch configuration is set to your Project name, and your main class.
Related
Been looking for around 2 hours for a solution to my problem, tried countless solutions and still the problem remains unsolved.
I have a game project with few packages; geometry, levels, decoration, and game. Inside the game package resides a gameRun.java
package game;
public class gameRun {
/**
* Program entry point.
* #param args the arguments for the levels
*/
public static void main(String args[]) {
... some code
}
}
and I have the following manifest file :
Main-Class: game.gameRun
Class-Path: someExternalGraphicTool.jar
//newline here
I compile my whole game using the following command : (the bin folder already exists).
javac -d bin src/geometry/*.java src/decoration/*.java src/levels/*.java src/game/*.java
I then turn my compiled classes into an executable .jar file using the command :
jar cvfm t.jar manifest.mf bin/geometry/*.class bin/decoration/*.class bin/levels/*.class bin/game/*.class
I then try to run my t.jar using :
java -jar t.jar
//or
java -cp .:t.jar game.gameRun
which both produce the error, "Error: Could not find or load main class game.gameRun"
However, when I unzip the jar file, inside the bin/game directory I can see a gameRun.class file and inside the META-INF\MANIFEST.MF file I can still see that the Main-Class is set to game.gameRun.
Note that I am working on a remote linux server, on a command line, and the jar file doesn't work even if I download it to my windows 10 machine.
What did I do wrong during this process ? Thanks for any help.
Your classes are in a wrong structure inside a jar file, because of the bin folder. My suggestion: pack it all into a jar starting in a bin folder.
Now when you extract your jar you will see 2 folders: META-INF and bin.
If you make the jar from bin folder you will see: META-INF and game, and it will work.
It doesn't work for you simply, because it can't find the main class, since it is inside the bin/game/YourClass.class, not in game/YourClass.class.
...\bin> jar cvfm t.jar manifest.mf geometry/*.class decoration/*.class levels/*.class game/*.class
And then just:
...\bin> java -jar t.jar
I'm trying to run a project from the command line (Ubuntu 14.04). The main class is called Demo, and I have a Demo.java, a Demo.class, and a Demo$1.class all in the same directory (I know it would be better to seperate them).
I wrote my own Manifest file, MANIFEST.MF, which just looks like this:
Main-Class:Demo
I made sure to end it with a newline.
Next, I want to create my .jar file. I did so with this command:
jar -cfm example.jar MANIFEST.MF *.class
Then, I try to run my project like so:
java -Djava.library.path=/path/to/dependencies -jar example.jar
I seem to get the following error no matter what I try:
Error: Could not find or load main class Demo
I've actually never compiled/run a Java project from the command line before, it's possible I'm making a stupid mistake and just can't figure it out. Any help is appreciated!
EDIT: Here are the contents of example.jar, according to vim:
" zip.vim version v27
" Browsing zipfile /home/ellen/bendersexample2/src/bendersexample/example.jar
" Select a file with cursor and press ENTER
META-INF/
META-INF/MANIFEST.MF
AnnotatedBenders.class
Demo$1.class
Demo.class
Demo$ModelType.class
ManualBenders$1.class
ManualBenders$BendersCallback.class
ManualBenders.class
Model.class
Problem.class
Solution.class
Solution$Verbosity.class
StandardModel.class
Here are the contents of the META-INF/MANIFEST.MF which is in the jar:
Manifest-Version: 1.0
Created-By: 1.8.0_161 (Oracle Corporation)
Main-Class: Demo
UPDATE: Here are the interesting parts of Demo.java:
package bendersexample;
public final class Demo {
/* Some functions */
public static void main(final String[] args) {
/* Some code */
}
}
I changed my MANIFEST.MF to the following:
Main-Class:bendersexample.Demo
And re-generated the example.jar file. I still get the following:
Error: Could not find or load main class bendersexample.Demo
Could there be an issue with how I generate my class files?
To generate the class files initially, I did the following:
javac -classpath .:/opt/ibm/ILOG/CPLEX_Studio_Community128/cplex/lib/cplex.jar *.java
Please let me know what else I should try! Thank you
The problem was just that had the Manifest in the /bendersexample folder and the was creating the .jar in this folder as well! I just needed to move that stuff into the parent directory and everything worked fine!
The final Manifest file used bendersexample.Demo as the Main-Class, and the jar was created and run from /bendersexample 's parent directory.
If anyone runs into this problem I would recommend taking a look at your project's structure before trying anything else, because this turned out to be a very easy fix!
I have just created a program that uses file I/O and for interactive input and output it uses terminal window of IDE. I want to create a executable jar file of this program. Is it possible? If yes, then how?
I am using BlueJ as IDE.
The program have **no GUI component**
I have created a jar using BlueJ but it does not works.. When I double click on jar nothing happens...
You have to have an Main-Class entry in your Manifest. See documentation for details.
Given yours example
public class MainClass {
public static void main(String agrs[]) {
System.out.println("magic");
MainClass.interning_behaviour("12");
}
public static void interning_behaviour(String string_input) {
String string="12";
String string_5;
string_5=string_input.substring(0);
System.out.println(string==string_5);
}
}
1) You have to compile it: javac MainClass.java
2) You have to jar it jar cfe MainClass.jar MainClass MainClass.class
3) Now you can run it java -jar MainClass.jar
basically you should type:
jar cf jar-file input-file(s)
You can find usage details at link below:
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
It depends on the IDE you're using.
In eclipse for example you can do this by right-clicking the package in package explorer window and navigating Export ->Java -> JAR file.
Export as a runnable jar if you're in eclipse
(Using JDK7)
A friend of mine asked me to write him a program for rolling dice of arbitrary number and size. So I did. For simplicity's sake, I kept it as a console app. Now I'm trying to distribute it to him. I tried exporting it as a Runnable Jar with Eclipse's built-in exporter.
After opening it with Java (As opposed to javaw)... Nothing happens. I'm able to take a screenshot of the command prompt before it closes, and it reads:
Error: Could not find or load main class C:\Users\Matt\Desktop\Roller.jar
Contents of Roller.jar
META-INF/MANIFEST.MF
roller/Roller.class
Contents of MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: .
Main-Class: roller.Roller
Contents of Roller.java:
public class Roller{
/* Irrelevant code expunged */
public static void main(String[] args){
//Irrelevant code expunged
}
}
I want to get this in a state where I can just email him the .jar and he can double-click it to run it. Can anyone help?
In Roller.java, you need to add package roller; to the top of your class to match Roller.class being in the roller folder in the JAR file. After this, you don't even need to specify a Class-Path in your Manifest file.
so I have a project that only has one class Main:
public class Main{
public static void main(String[] args) {
System.out.println("asdf");
System.out.println(args[0]);
System.out.println(Integer.parseInt(args[1]));
}
}
so I tried to export this as a standalone jar...here's what I did
created a run configuration for the project...the run configuration runs properly from eclipse...it prints the arguments just fine...
right click on the project, selected export
choose the runnable jar file option
selected my previously created run configuration as the run configuration, chose export destination press finish, etc
but then when I run the program from the commandline:
Main.jar "testtest" 123
nothing came up.....it didn't print out the arguments....nor did it print out the "asdf" I specified in the main() function...
what did I do wrong?
Run java -jar Main.jar "testtest" 123 ?
I think you are getting wrong what exporting as a runnable jar means: This does not create an executable file. It just creates an archived file with all your compiled classes and some special meta information about which class to run when invoked with java -jar JARNAME.
Note that this also means all users of your program still need to have a java runtime installed.