0

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 :(

  • http://stackoverflow.com/editing-help – SLaks May 27 '13 at 17:16
  • 1
    [How to build an executable jar](http://stackoverflow.com/questions/502960/eclipse-how-to-build-an-executable-jar-with-external-jar) But you don't really want that, since you want to run you code as a Java applet. You confuse quite a lot of stuff in your question so my guess is that to get a usable response you will need to provide quite some more details. – noamik May 27 '13 at 17:18
  • details such as? i want to be able to make a jar file that i can just doubleclick and that it starts running. if you need any info, ask me :) – Stijn De Winter May 27 '13 at 17:20
  • It's strange that Eclipse doesn't do the job; it certainly works for me. What do you mean by "when i try to set 'Main.class' as main class, then it's not in the list": what list? The one you get when you press the "Browse" button? That suggests you aren't exporting the right class files. – Arend May 27 '13 at 20:36

4 Answers4

1

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>
kgdesouz
  • 1,966
  • 3
  • 16
  • 21
0

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

carej
  • 596
  • 1
  • 6
  • 18
  • well, i have no idea how i do so. what i found on the internet is that i need to set "Main-Class: MyPackage.MyClass", but i have no idea how. just edit in noteblock? and what to? my main class is "main.class" – Stijn De Winter May 27 '13 at 17:25
  • Yes, you can edit the manifest in any text editor. Just make sure you put the edited file back into the jar. In your case the correct line would be `Main-Class: main` – Arend May 27 '13 at 20:28
0

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

Community
  • 1
  • 1
Cesar Loachamin
  • 2,740
  • 4
  • 25
  • 33
  • i tried everything your link suggests, altho i don't have " /nbproject/project.properties" so i don't know where i should put that line... – Stijn De Winter May 27 '13 at 18:46
0

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

Ali
  • 1,480
  • 2
  • 20
  • 30