Stijn De Winter
Stijn De Winter

Reputation: 3

How to make a runnable .jar file?

for school i have to make a game, together with 2 classmates. our group had to make something in Java, a language we never used before. we got ourselfs a little game now, but we can't seem to get it into a working .jar file nor a runnable jar. We use eclipse, but the .jar file created through export => jar file doesn't work. it doesn't do anything. (manifest file is totally empty) the runnable jar file is even worse, it says there is no main class selected, but when i try to set 'Main.class' as main class, then it's not in the list. (at advanced options for creating a runnable jar in Eclipse) i tried through cmd too, but then it couldn't find a manifest attribute... any help? my maps: -Smash'em All -.settings - bin -data (all my images and such) -Smash (all the .class files) -java.policy.applet - src -data (some old pictures, not the same as in the other data map) -Smash (all the .java files) - .classpath - .project

any idea how to make a runnable jar? and if i want to implement it in HTML, do i need a runnable or just a .jar file? EDIT: my lay-out doesn't seem saved? :( sorry, is my first post ever herer :(

Upvotes: 0

Views: 2585

Answers (4)

Ali
Ali

Reputation: 1590

you can make use of exe4j tool, which takes your classes in jar and produce exe for you. try this http://www.ej-technologies.com/products/exe4j/overview.html

Upvotes: 0

kgdesouz
kgdesouz

Reputation: 1996

To add to Césars' comment, have you tried:

jar cvf YourApplication.jar *.class

From "Java How to Program" :

That should jar up your classes which creates in the current directory a JAR file named YourApplication.jar containing the applet’s .class files. If the program had other resources, you’d simply add the file names or the folder names in which those resources are stored to the end of the preceding command. The letters cvf are command-line options to the jar command. The c option indicates that the command should create a new JAR file. The v option indicates that the command should produce verbose output so you can see the list of files and directories being included in the JAR file. The f option indicates that the next argument in the command line (YourApplication.jar) is the new JAR file’s name.

As per one of your questions, you asked "if i want to implement it in HTML, do i need a runnable or just a .jar file". No, you can just run the class file, if you want.

<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <applet code = "YourApplication.class" width = "300" height = "45">
        </applet>
    </body>
</html>

Upvotes: 1

Cesar Loachamin
Cesar Loachamin

Reputation: 2738

To run you jar using the java -jar command or double click your jar you need to indicate the main class to run, you do it adding the Main-Class in the META-INF/Manifest.MF of your jar, in this link you can see how to setup the main class

Upvotes: 0

carej
carej

Reputation: 606

If you want some that can run with "java -jar" you need to specify the main class in the JAR manifest.

Upvotes: 0

Related Questions