• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tankyroo

[java] Exporting jar.

15 posts in this topic

Hey everyone, I'm having trouble exporting my first game as a .jar file, Here are the steps I'm using:

(I'm using eclipse)
Right-click on my project, click export.
Select type "JAR File".
Select my whole project, making sure all necessary files are selected.
Generate the manifest, select my main class as the main class.
Click finish, finishes exporting without any errors
Double click on the file that was just exported, and it gives me the error: "Could not find the main class: slickGame.src.MainClass. Program will exit."
Right click on .jar, open with WinRAR, go to META-INF, edit the manifest, everything is in order.
Contents of the manifest:
"Manifest-Version: 1.0
Main-Class: slickGame.src.MainClass

" (Yes there is a newline after.)

I'm not sure what is going wrong, I've tried searching but everything just tells me to edit the manifest which is already correct.

Not sure if this matters, but I'm using the Slick2D Library (hence the name slickGame.)
I'm also packaging the files for those to work. (dlls, slick.jar, and lwjgl.jar)

Any help is appreciated, thanks in advance.
0

Share this post


Link to post
Share on other sites
Have you verified the class files have been exported and put into the correct structure?

From the root of the jar, is there a "slickGame.src.MainClass.class"?
0

Share this post


Link to post
Share on other sites
[quote name='Angex' timestamp='1322517209' post='4888592']
Have you verified the class files have been exported and put into the correct structure?

From the root of the jar, is there a "slickGame.src.MainClass.class"?
[/quote]

I open up the jar, and I see multiple files/folders, I open the "slickGame" folder, then I open the "src" folder and in there I see MainClass.class, if that's what you mean.
0

Share this post


Link to post
Share on other sites
You should try running your program from the command line without the jar file. Make sure that works first.
If you put the /src folder in the jar file, the manifest won't find the class files, because it doesn't look in the "src" folder.

You could add the src folder to the classpath, but you haven't done that.
You would have the same problem if you opened a command window at the project and
tried to run the program.

Are you compiling by hand? Normally, with the default Eclipse project, the *.class files end up in the /bin folder.
If you didn't set it up to put the *.class files there, are you compiling with the command line?

Either way, if the only folder in your jar file is the slickGame package folder, it should work.
0

Share this post


Link to post
Share on other sites
[quote name='Glass_Knife' timestamp='1322527735' post='4888637']
You should try running your program from the command line without the jar file. Make sure that works first.
If you put the /src folder in the jar file, the manifest won't find the class files, because it doesn't look in the "src" folder.

You could add the src folder to the classpath, but you haven't done that.
You would have the same problem if you opened a command window at the project and
tried to run the program.

Are you compiling by hand? Normally, with the default Eclipse project, the *.class files end up in the /bin folder.
If you didn't set it up to put the *.class files there, are you compiling with the command line?

Either way, if the only folder in your jar file is the slickGame package folder, it should work.
[/quote]
First off, thanks for the reply.
Secondly, I'm still pretty new to java, so I don't know how to compile with the command line (or even where to find the command line to be perfectly honest.)

Edit: After a little bit, I figured out how to compile and everything with the command line, but while compiling I get errors from what I think is not having the slick2d library in the right place. I'll keep messing with it and report back soon.

Edit2: I still can't figure it out, I've spent a good amount of time on it, I'm going to take a break, maybe someone will reply with some more help by then.

Edit3: I don't know what's wrong, I followed a tutorial just to make a simple jar, and that doesn't work for me either, here are my steps:

Made a file named: hello.java
contents of hello.java: [code]
import javax.swing.JOptionPane;

public class hello{

public static void main(String[] args){
int fr = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog(null, "This is the body of the Executable's\rMessage Dialog.","Hello", fr);
System.exit(0);
}

}[/code]
Opened command prompt
changed directory to where it is located (C:\j)
> javac hello.java
> java hello

[code]
Exception in thread "main" java.lang.NoClassDefFoundError: hello
Caused by: java.lang.ClassNotFoundException: hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: hello. Program will exit.
[/code]

Anyone know why?
0

Share this post


Link to post
Share on other sites
[quote]Anyone know why?[/quote]
First, one of the nice things about Java (and .Net) style languages is that their errors are designed to be human readable. Thus, when you get an error such as [i]java.lang.NoClassDefFoundError[/i] you can generally copy + paste into Google and find something.

In this case, it looks like your classpath isn't set correctly. Take a look [url="http://docs.oracle.com/javase/tutorial/getStarted/problems/"]here[/url] for some possible solutions. The easiest would probably be to modify your command slightly to:

[left][i]> java -cp . hello[/i]
[/left]
Assuming that your hello.class file isn't in another directory. To permanently correct the issue (as by-hand solutions will fade when you reboot) you'll need to set the CLASSPATH variable to something sane using Windows' ENV-VAR dialog. Other culprits can be incorrectly setting JAVA_HOME although that usually manifests in being unable to find [i]javac[/i]. Also, it always helps to do a [i]dir[/i] (or [i]ls[/i]) after you compile to ensure Java generated your class files correctly (and in the correct place).

Once you've verified that [i]java[/i] works correctly, make a test jar:

[i]> [text editor] hello.mf[/i]
Main-Class: hello

[i]> jar cvfm hello.jar hello.mf *.class
> java -jar hello.jar[/i]

[quote]Edit: After a little bit, I figured out how to compile and everything with the command line, but while compiling I get errors from what I think is not having the slick2d library in the right place. I'll keep messing with it and report back soon.[/quote]
Sounds like you need to manually set both the class and library paths so that Java can find your dependencies. The classpath is so that Java may find your .class files (including those packaged in a jar) while the library path is for specifying native libraries to load at runtime. So you would do something like:

[i]> javac -classpath [path to required jars] [/i][i][arguments] [/i]
[i]> java -Djava.library.path=[path to native libraries] [arguments]
[/i]
Please note that if Java failed to compile correctly (for whatever reason) then you won't have a valid "main" class file. Thus, you will also get a [i]java.lang.NoClassDefFoundError[/i] if you attempt to run it from a jar.

For what it's worth, using a tool like Maven can make this much less aggravating.
1

Share this post


Link to post
Share on other sites
Well I finally got the tutorial example to work (not completely sure how) and I'm still running into problems with my game, I tried doing it the same way as the one that just worked, but I get 47 errors, most of them are like this: [code]
cannot find symbol
symbol : variable Keyboard
location: class src.Platformer // (Trying to compile another file to see if that will work, that's why the name isn't slickGame like in the original post.)
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE))
^
method does not override or implement a method from a supertype[/code]
0

Share this post


Link to post
Share on other sites
[quote name='Tankyroo' timestamp='1322766447' post='4889527']
I'm not sure what the rules say about bumping, but I still can't figure this out.
[/quote]

Hello. I think there are some problems in the Keyboard class in the library. did you compile it with Eclipse? If so you click with right button of the mouse on the project. Click properties. Then look for java build path...
There should be everything you need about how to compile the program. Remember that you can run directly your application from eclipse without having to compile from the command line. Everything it should be automatic and should solve all your problems and lack of times about configurations.
It may be that you lack some library or maybe they change the protection of some constants, maybe before they were public and now they are private and they should be accessed with getCONSTANT getter method.

Remember about assembly dependencies too in the properties window. There you can specify what you want to export and in which directory.
I hope I can help
0

Share this post


Link to post
Share on other sites
[quote name='m3rlino' timestamp='1322768005' post='4889552']
[quote name='Tankyroo' timestamp='1322766447' post='4889527']
I'm not sure what the rules say about bumping, but I still can't figure this out.
[/quote]

Hello. I think there are some problems in the Keyboard class in the library. did you compile it with Eclipse? If so you click with right button of the mouse on the project. Click properties. Then look for java build path...
There should be everything you need about how to compile the program. Remember that you can run directly your application from eclipse without having to compile from the command line. Everything it should be automatic and should solve all your problems and lack of times about configurations.
It may be that you lack some library or maybe they change the protection of some constants, maybe before they were public and now they are private and they should be accessed with getCONSTANT getter method.

Remember about assembly dependencies too in the properties window. There you can specify what you want to export and in which directory.
I hope I can help
[/quote]

I tried what you said, but I couldn't find anything that looked wrong.

What I did was add this to my manifest: [code]Class-Path: lib/lwjgl.jar lib/slick.jar[/code]
And that fixed my previous error, but now what happens is when I try to open the jar file, the game window opens but closes immediately (Progress!). Any insight as to why?

Edit: I didn't only add that Class-Path code to the manifest, I also put the required files outside of the jar in the same folder, but I'm still having that problem where it opens and closes.
0

Share this post


Link to post
Share on other sites
[quote]Once again, sorry for the bump, but I'm really stuck on this.[/quote]
Relax, it's fine.

[quote]And that fixed my previous error, but now what happens is when I try to open the jar file, the game window opens but closes immediately (Progress!). Any insight as to why?[/quote]
First, what is it you are actually doing? Is this a simple "Hello, World!" but with your application requiring the other two as a test? We can help you better if you show us what it is you're trying to do - e..g what does the "main" portion of your application look like (in code)? That said, if you're certain your application isn't bailing immediately for some reason then don't worry about it.

Second, are there no errors? In this same vein, are you passing on any exceptions (e.g. just using empty [i]catch(){}[/i] blocks) that might give an indication of a problem?

I'm not trying to be obtuse but I think there's some confusion regarding what you've actually done at this point. So, if I read this aright you've:

[list][*]Compiled your application successfully.[*]Packaged your application into a .jar[*]Packaged your dependencies (LWJGL and Slick) into the jar as well.[*]Altered the manifest so that your application can find your dependencies correctly.[*]Tried to run the application and it just "starts then stops".[*]??? output ???[/list]
One of the key steps missing is what you did with the native libraries (.dll, .so, or .dynlib depending on your platform) as those are required for your application to run correctly.
0

Share this post


Link to post
Share on other sites
[quote name='Kyan' timestamp='1322901903' post='4890083']
[quote]Once again, sorry for the bump, but I'm really stuck on this.[/quote]
Relax, it's fine.

[quote]And that fixed my previous error, but now what happens is when I try to open the jar file, the game window opens but closes immediately (Progress!). Any insight as to why?[/quote]
First, what is it you are actually doing? Is this a simple "Hello, World!" but with your application requiring the other two as a test? We can help you better if you show us what it is you're trying to do - e..g what does the "main" portion of your application look like (in code)? That said, if you're certain your application isn't bailing immediately for some reason then don't worry about it.

Second, are there no errors? In this same vein, are you passing on any exceptions (e.g. just using empty [i]catch(){}[/i] blocks) that might give an indication of a problem?

I'm not trying to be obtuse but I think there's some confusion regarding what you've actually done at this point. So, if I read this aright you've:

[list][*]Compiled your application successfully.[*]Packaged your application into a .jar[*]Packaged your dependencies (LWJGL and Slick) into the jar as well.[*]Altered the manifest so that your application can find your dependencies correctly.[*]Tried to run the application and it just "starts then stops".[*]??? output ???[/list]
One of the key steps missing is what you did with the native libraries (.dll, .so, or .dynlib depending on your platform) as those are required for your application to run correctly.
[/quote]
That is what I've done, you have read it right.
My dlls and everything are both in the jar in a folder called "lib" (just like they were in eclipse) and they are also outside of the jar with the same folder name just in case.

This is the "main" portion of my code (If this isn't what you mean, I can post other stuff.):
[code]public static void main(String[] args) throws SlickException{
AppGameContainer app = new AppGameContainer(new Platformer());
app.setDisplayMode(800, 600, false);
app.start();

}[/code]

And yes, when I run the .jar the only thing that happens is the window opens, and then closes immediately, before anything loads, so the glimpse that I see of it is just a while screen, no title or anything either.

Also, about output, there are no errors or anything.

Edit: It looks like I finally got it to work!

Thank you everyone for your help!




for people who might have this same problem, here is what I did:
In command prompt I changed the directory to where everything is located.
I then entered:
>java -Djava.library.path=C:\j\lib -jar test.jar (C:\j\lib is where my library files are. lwjgl.jar, slick.jar, and all of the .dlls that go with it.)
And that opened my program successfully!
But, I didn't want to open command prompt to use my program every time.
So in the same directory as my jar and the necessary files, I made a batch file named run.bat.
The contents of the .bat are the same as I entered in command prompt. (java -Djava.library.path=C:\j\lib -jar test.jar)
Now all I have to do is open run.bat and it will run my game!
I hope this helps people who have a similar problem so they won't have to spend nearly five days trying to figure it out.
0

Share this post


Link to post
Share on other sites
When doing some JNI work, I found it necessary to add the folder containing the *.dll files to the system PATH.
Once I had done that, (this was trying to access native libraries with TOMCAT), and after I rebooted the
computer everything worked.

I think if you add that folder with the *.dll files to the PATH, you won't need to do any magic with the script.
0

Share this post


Link to post
Share on other sites
You could also try to programmatically set the Java startup variables.
[source lang="java"]System.setProperty("java.library.path", "%String%");[/source]
P.S. I didn't test the code above
0

Share this post


Link to post
Share on other sites
[quote name='Tankyroo' timestamp='1322933702' post='4890171']
In command prompt I changed the directory to where everything is located.
I then entered:
>java -Djava.library.path=C:\j\lib -jar test.jar (C:\j\lib is where my library files are. lwjgl.jar, slick.jar, and all of the .dlls that go with it.)
And that opened my program successfully!
[/quote]
Ridiculously, you can't usually package dependant jars or native libraries within a jar. Nothing stops you putting them in there but the standard classloader won't inspect them. This is why it only works once you direct it to your external dependencies. The usual thing to do is simply to not even try and package them in jar. A good-looking solution that I've never tried would be to use a 3rd party classloader like http://www.jdotsoft.com/JarClassLoader.php, it also allows packaging of native lib too. Edited by dmatter
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0