Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problems creating jar files.  (Read 3093 times)
0 Members and 1 Guest are viewing this topic.
Offline Grobinson

Senior Newbie





« Posted 2012-03-30 16:12:19 »

I typically use Eclipse to do all my java programming in and when I use it to test my programs it works great. No problems at all with it so far. My problems are coming in when I try to create an executable jar file. It doesn't matter if I use Eclipse to make it or do it through command, I always end up with the same error of "Could not find the main class: Main" I have followed written guides on it and even some YouTube videos for a visual example. Why is it that it's not able to find the main class?
Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-03-30 16:32:09 »

It looks like you're using the default package.  You need to give Eclipse's jar exporter the full package name of your main class, e.g. com.foo.mygame.Main.  If you're doing it by hand with the jar command, you need to make sure you have a META-INF/MANIFEST.MF file that contains "Main-Class: com.foo.mygame.Main" somewhere in it.

If your Main class, or any other class, is in the default package, then by jove move it the hell out of there.  Don't ever use the default package, it can lead to a lot of subtle weird issues.
Offline Grobinson

Senior Newbie





« Reply #2 - Posted 2012-03-30 16:45:26 »

It looks like you're using the default package.  You need to give Eclipse's jar exporter the full package name of your main class, e.g. com.foo.mygame.Main.  If you're doing it by hand with the jar command, you need to make sure you have a META-INF/MANIFEST.MF file that contains "Main-Class: com.foo.mygame.Main" somewhere in it.

If your Main class, or any other class, is in the default package, then by jove move it the hell out of there.  Don't ever use the default package, it can lead to a lot of subtle weird issues.


I have tried a few variations of that and in every form I've tried it always has the same error.

EDIT:

As a small example to try and figure this out I had this code.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
package com.game.mygame;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
public class Main {
 
   public static void main(String[] args) {
 
       Frame f = new Frame();
       f.addWindowListener
             (new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {
                    System.exit(0);
                    }
                 }
       );  
       f.add(new Label("This JAR file is executable!"));
       f.setSize(500,500);
       f.setVisible(true);
   }
}


I was also using this in my manifest.txt file.
1  
Main-Class: com.game.mygame.Main


I have tried making an executable jar file in command, eclipse, and net beans, none of which seem to be able to find the main class.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline H3rnst

Senior Newbie


Medals: 1



« Reply #3 - Posted 2012-03-30 21:20:49 »

Here's what I do when I want to create an executable jar from a new project:

- In the Package Explorer, right click on the project folder.
- Run As -> Run Configurations.
- On the left of the window, right click on Java Application -> New (After this you should have a subset option below Java Application)
- On the right part of the window you should have a 'Search' button next to a 'Main class' label. Click on it and start typing the name of your main class. It should appear in the 'Matching items' list. Click OK.
- Click Apply, and Close.
- Go back to the Package Explorer, right click on the project folder.
- Export -> Java folder -> Runnable JAR file -> next.
- In 'Launch configuration' select the launch configuration you've just created.
- In 'Export destination' choose where you want the JAR file to be saved.
- If you have referenced libraries in your project, click the option "Package required libraries into generated JAR"
- Click Finsh.

Hope this helps!


Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2012-03-30 21:46:28 »

Do you have a copy of the JAR so we can poke through it to see what's wrong?

Offline sproingie

JGO Kernel


Medals: 202



« Reply #5 - Posted 2012-03-30 22:52:46 »

I was also using this in my manifest.txt file.

It has to be named MANIFEST.MF and be in a directory called META-INF in the root of your jar.
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2012-03-31 00:45:21 »

I was also using this in my manifest.txt file.

It has to be named MANIFEST.MF and be in a directory called META-INF in the root of your jar.
I bet he was talking about the manifest.txt file you give the JAR command line tool Wink

Offline sproingie

JGO Kernel


Medals: 202



« Reply #7 - Posted 2012-03-31 00:53:26 »

Right, I always forget about the -m flag.  And the error would have been different for a missing main-class entry anyway ... ah well, thought I had an easy one for a moment Smiley
Offline H3rnst

Senior Newbie


Medals: 1



« Reply #8 - Posted 2012-03-31 01:39:08 »

I was also using this in my manifest.txt file.

It has to be named MANIFEST.MF and be in a directory called META-INF in the root of your jar.


I've never said that!!  Huh Grin

Offline Grobinson

Senior Newbie





« Reply #9 - Posted 2012-03-31 02:32:11 »

Here's what I do when I want to create an executable jar from a new project:

- In the Package Explorer, right click on the project folder.
- Run As -> Run Configurations.
- On the left of the window, right click on Java Application -> New (After this you should have a subset option below Java Application)
- On the right part of the window you should have a 'Search' button next to a 'Main class' label. Click on it and start typing the name of your main class. It should appear in the 'Matching items' list. Click OK.
- Click Apply, and Close.
- Go back to the Package Explorer, right click on the project folder.
- Export -> Java folder -> Runnable JAR file -> next.
- In 'Launch configuration' select the launch configuration you've just created.
- In 'Export destination' choose where you want the JAR file to be saved.
- If you have referenced libraries in your project, click the option "Package required libraries into generated JAR"
- Click Finsh.

Hope this helps!


This has it fixed in eclipse at least. now I just have to figure it out for command as I feel it would be needed.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Fokusas
« Reply #10 - Posted 2012-03-31 07:06:59 »

Jar file is simple archive with .jar ending and you can create with any compressor (7zip or other). And to make it executable it should contain META-INF/MANIFEST.MF file that contains "Main-Class:yourClass"
Offline _Al3x

Senior Duke


Medals: 7


Indie Games FTW!


« Reply #11 - Posted 2012-04-01 16:45:23 »

Probably this should´t go here but I didn´t want to create another thread, because I think it fits here. Smiley

I try to create an executable jar using export (in eclipse), but the resulting jar doesn´t run at all. I get no errors. The project runs great inside Eclipse, but I´d like to create the executable jar so I can share it!

I did what H3rnst said but still, it doesn´t run.

The main class:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
package AEI.main;

import AEI.engine.GameEngine;


public class Main{
   public static void main(String[] args) {  
      GameEngine game = new GameEngine();
      game.run();
   }  
}


Is it because "run" it´s in the engine? But that should´t be a problem, since it´s called just fine from main  Undecided

Thanks!

Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #12 - Posted 2012-04-01 17:09:26 »

Again, please provide a JAR. Its quite hard to diagnose your problem blindly. Smiley

Offline H3rnst

Senior Newbie


Medals: 1



« Reply #13 - Posted 2012-04-02 03:05:14 »

I try to create an executable jar using export (in eclipse), but the resulting jar doesn´t run at all.
I did what H3rnst said but still, it doesn´t run.

Try to run it from console with the following command:
1  
java -jar your_game.jar

and it should display some kind of error. Tell us what is it, or do as ra4king says and upload the .jar you're having problems with.

Offline _Al3x

Senior Duke


Medals: 7


Indie Games FTW!


« Reply #14 - Posted 2012-04-02 23:31:24 »

Try to run it from console with the following command:
1  
java -jar your_game.jar

and it should display some kind of error. Tell us what is it, or do as ra4king says and upload the .jar you're having problems with.

Thanks mate, somehow the IDE didn´t refresh the sprites folder and was using an "old cached one" (HuhHuh) so no errors while running from eclipse, but I did what you said and said that it didn´t find the sprites (which I had renamed -_-).

I pressed F5 a lot and finally Eclipse told me the same error, so everything works now, thank you Smiley
(and ra4king, thank you too mate)

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (38 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!