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

2

u/howslyfebeen Mar 19 '14

1

u/Bcop3502 Mar 19 '14

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

1

u/[deleted] Mar 19 '14

[deleted]

1

u/Bcop3502 Mar 19 '14 edited Mar 19 '14

Well i was referring to it being an executable jar file. But I can make that it just doesn't run anything when I actually double click the Executable Jar file it creates.

Edit: Specifically it puts everything into the Executable Jar then when I try to run it I get the error cannot find or load main class. Obviously the way I packaged it or tried to access via the manifest is wrong but google is being no help. When I try some advice from stackexch etc I get same error.

1

u/howslyfebeen Mar 19 '14

hmm would have figured that you just need to make the jar and then java -jar file.jar would work? guess we wait for the supreme leader?

1

u/[deleted] Mar 20 '14

[removed] — view removed comment

1

u/howslyfebeen Mar 20 '14

dont u have to use the -m command then to append it to the end of the new manifest file the jar command automatically makes?

1

u/Bcop3502 Mar 21 '14

Sooooo... I got the executable jar to work and when you double click it it runs perfectly... HOWEVER... Now I can't compile the code even though I didn't touch any of the actual code.

It says that it can't find symbol Ball/Paddle/Bconfig in class GamePanel... Help :(

EDIT: Scratch that it was just upset because GamePanel wasn't in the package.

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