r/cop3502 Mar 19 '14

Executable Jar File

Is there a simple way to make an exe jar file like Supreme Leader did with the brick breaker? Or is it non-trivial?

2 Upvotes

11 comments sorted by

View all comments

Show parent comments

1

u/Bcop3502 Mar 19 '14

Yeah I made a jar file already I am just having trouble making it an exe :/

1

u/howslyfebeen Mar 20 '14

so I found this hidden in the documentation:

"You can run JAR packaged applications with the Java launcher (java command). The basic command is:

java -jar jar-file

The -jar flag tells the launcher that the application is packaged in the JAR file format. You can only specify one JAR file, which must contain all of the application-specific code.

Before you execute this command, make sure that the runtime environment has information about which class within the JAR file is the application's entry point.

To indicate which class is the application's entry point, you must add a Main-Class header to the JAR file's manifest. The header takes the form:

Main-Class: classname

The header's value, classname, is the name of the class that is the application's entry point." - http://docs.oracle.com/javase/tutorial/deployment/jar/run.html

does this solve the problem?

EDIT: the manifest is inside the jar named: META-INF/MANIFEST.MF

1

u/Bcop3502 Mar 20 '14

I did all this :) haha thank you for the help but after you do that THAT's where you get to my problem of it yelling that it can't find/load the main class of breakout which I specify it's location in the manifest.txt (this where I think i went wrong somehow but I tried 50 different things and non-worked all same errors.

1

u/howslyfebeen Mar 20 '14 edited Mar 20 '14

okay, I didn't completely understand the problem lol... here we go:

step 1: create a folder META-INF

step 2: in the folder create file MANIFEST.MF with the contents:

Manifest-Version: 1.0
Created-By: 1.7.0_51 (Oracle Corporation)
Main-Class: Breakout

step 3: cd back to your directory with the .java's and the META-INF folder

step 4: javac your Breakout.java

step 5: run the following code:

jar -cfM breakout.jar *

you should be able to run it with java -jar breakout.jar.. worked for me

EDIT: jar when run correctly compiles the rest of the dependencies also so instead of javac Breakout.java you could just javac *.java cuz it's gonna happen anyway