• 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
Nicholas Kong

How to run a Java jar file without a MS DOS batch file

16 posts in this topic

So I have been working on my game for a little over a month. Even with college, I spend as much time as I can on the game to be bug-free as possible and make sure it is important it has the right mechanics of that particular genre.

 

Now I want to share it with people and make sure they can play it by clicking the jar file instead of the MS DOS batch file I created. This would mean the src folder will not be given along side with the Java jar file. 

 

directory_zps0692df20.png

 

I know for certain it is possible seeing as I have downloaded and use other people jar files and their jar files do not come out a src folder or a batch file. How did they do it?

Edited by warnexus
0

Share this post


Link to post
Share on other sites

What does your batch file contain? I'd expect this to be out of your control, because for instance, WinRAR typically associates itself with .jar files by default, which means if the user has his system settings set to user WinRAR (or something else) in precedence to Java for .jar files, double-clicking the file will not run the game, and there's not much you can do about that. You could have an installer which reinstates proper file associations, but that is *very* unusual practice for a game.

 

In this case, though, it seems your file associations are correct, I believe you need to write an additional method - probably to set the entry point - to be able to run from the .jar without invoking java directly (which I guess is what your batch file is doing) but I don't know any further off the top of my head. Did you try reading this?

0

Share this post


Link to post
Share on other sites

If file associations are correctly set up I would recommend using OneJar (http://one-jar.sourceforge.net/). I've used this for prototypes. It can even load native libraries such as LWJGL.

Other solutions you could use are:

0

Share this post


Link to post
Share on other sites

 

One tool I would recommend for this purpose is Launch4j.

@warnexus It looks like you're targeting Windows, but if you target other platforms you could build one executabe wrapper for each platform.
 
I once had a problem where I created an executable JAR file that worked by double-clicking on my computer but it didn't work on another computer. It could have been an issue involving a JRE difference. The other advantages of using a tool such as Launch4j is that JRE differences are handled automatically (you either bundle your JRE version or you set a min and max version) and you don't have to worry about the user having to set the Java path.

Edited by shacktar
1

Share this post


Link to post
Share on other sites

Now I want to share it with people and make sure they can play it by clicking the jar file instead of the MS DOS batch file I created. This would mean the src folder will not be given along side with the Java jar file.

I'm just wondering if you are having a problem with the OS not executing the jar file when clicked, or are you not setting the Main-Class: in the manifest file of the class path. As pointed out above, if the user doesn't have the file associations configured, there is not much you can do. However, there is nothing wrong with having a batch file or shell script to launch your program. ANT does this, for example.

Using launch software to generate an executable for the target OS to launch the Java code behind the scenes seems like overkill for a small game. Edited by Glass_Knife
0

Share this post


Link to post
Share on other sites

What does your batch file contain? Did you try reading this?

I actually did come across the same link but my jar cannot execute unless it has the src folder that has the .class files. when I use other people's jar file. I do not even see the .class files only just one .jar file to execute the program.

 

My batch file is basically a .txt file with these commands: Here's a picture of what is inside the .txt

 

On a side note I do not understand what "-cp" means.

 

 

 

batch_zpsec4cb42f.png

 

 

I already written the manifest. then I tried this command java -jar NicholasGame.jar in the command prompt and it worked but for the average user this would be weird to do. If I execute my jar file without the src folder my application becomes like this. 

 

blank_zps0222e1df.png

Edited by warnexus
0

Share this post


Link to post
Share on other sites

You could add/edit the jar manifest to include/specify which class is the startign point.

 

See http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html for more details.

I did add the Manifest. Here is what the Manifest looked like. Should it be in the src folder or outside of the src folder? But the manifest did not help me access the jar file. I even tried to java -jar JAR-name (ie java -jar NicholasGame.jar )on the command prompt and it worked but for the average user this is weird to perform just to open a game.

 

manifest_zps0c7b2f74.png

Edited by warnexus
0

Share this post


Link to post
Share on other sites

If you're using Eclipse then you can go to "File->export->Java->Runnable Jar file" to create an executable Jar. 

 

As for shipping the source code - whether you make a runnable JAR or use a batch file you shouldn't need to include a copy the source code. When delivering a batch file all you need to ship with it are the compiled .class files and your batch script can invoke Java on those. My guess is that your current batch file is invoking javac (the java compiler) and compiling the source on the fly? Or perhaps you don't realise that once the .class files are generated Java doesn't require the .java source files to actually run the program.

I followed your instructions but I got export errors which is odd because my game runs fine without errors on Eclipse.

 

Here's what export errors showed.

 

exporterrors_zpsf8567826.png

 

I'm not providing the source code to the user. All source code been compiled into .class files. I actually provided what my batch file is doing above. The batch file is basically a .txt that says "java -cp  NicholasGame.jar Game". what exactly does "-cp" mean? I know the batch file is one way which I already performed before making this thread but I have used other people jar files and all I needed to do was click the jar file and run the application and they did not have any .class files with the jar file

Edited by warnexus
0

Share this post


Link to post
Share on other sites

I'm just wondering if you are having a problem with the OS not executing the jar file when clicked, or are you not setting the Main-Class: in the manifest file of the class path. As pointed out above, if the user doesn't have the file associations configured, there is not much you can do. However, there is nothing wrong with having a batch file or shell script to launch your program. ANT does this, for example.

Using launch software to generate an executable for the target OS to launch the Java code behind the scenes seems like overkill for a small game.

Now it seems I cannot execute the jar unless it has the src file(which has the .class files) along side with it. I think when I use other people jar files, the programmers already put the src file inside the jar file. I want to know how I can do that.

 

If there is nothing wrong for the user to click the batch file then I will just let them do that. The reason why I did not want to do it that way was because I did not need to run a batch file when I used other people's jar files.

0

Share this post


Link to post
Share on other sites

what exactly does "-cp" mean?

The -cp flag is short for -classpath, which tells the java command where to look for the class files. If you didn't put *.jar file in the classpath, then Java would not be able to find the code.

The source files do not have anything to do with the jar file working. A jar file is just a *.zip file renamed to *.jar. You could create the jar file as a zip file by hand, including the source code, and then change the extension to *.jar.

However, most people, for creating jar files like this, either do it from the command line or use http://ant.apache.org/

Something looks weird with your class files. They need to be in the package folders in the jar, and you shouldn't be using classes without at least one package. In the past, I have had trouble getting code without any packages to work like this. It seems like something is wrong, because I see your game is called Game, but I also see a Game folder in the jar screenshot.

One thing, is that the main class needs the fully qualified java name. For example, a typical manifest for my games looks like this:

Main-Class: tim.game.app.ReallyAwesomeGame

// ReallyAwesomeGame.java
package tim.game.app; // VERY IMPORTANT!!!

When compiled there with be a folder for each package level, and the Really AwesomeGame file must be in the package structure inside the jar file.

tim
- game
- app
ReallyAwesomeGame

If this stuff isn't exactly right, it won't work.
1

Share this post


Link to post
Share on other sites

Something looks weird with your class files. They need to be in the package folders in the jar, and you shouldn't be using classes without at least one package. In the past, I have had trouble getting code without any packages to work like this. It seems like something is wrong, because I see your game is called Game, but I also see a Game folder in the jar screenshot.

 

Game.class is the entry point. I have another folder called "Game" and that contains an image for the gameover. I guess I should change the name of the folder to avoid confusion

Edited by warnexus
0

Share this post


Link to post
Share on other sites
The last time I tried to create an executable jar with classes that we not in any packages, I couldn't get it to work. It seemed like a bug, but putting them in at least one package can't hurt.

Try it and see.
0

Share this post


Link to post
Share on other sites

The last time I tried to create an executable jar with classes that we not in any packages, I couldn't get it to work. It seemed like a bug, but putting them in at least one package can't hurt.

Try it and see.

when you're talking about one package, can I use the default package or should I create my own package? I will try this.

0

Share this post


Link to post
Share on other sites

when you're talking about one package, can I use the default package or should I create my own package? I will try this.

create at least one package. The name doesn't really matter. Long ago, in the Java 4.1 days, I tried created a Jar with files that had no package (because I was being lazy and didn't want to create a folder) but it didn't work. That may have been fixed. I've always used at least one package since, and have never tried it without one.
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