Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  I'd like to get an executable jar file made from my LWJGL project  (Read 2190 times)
0 Members and 1 Guest are viewing this topic.
Offline ShadowProtocol

Senior Newbie





« Posted 2010-12-01 02:03:04 »

Hi everyone, I've been learning LWJGL and I have a program right now I'd like to send to my friends. It's dependencies are Slick_util.jar, lwjgl.jar, and lwjgl_util.jar.   I am using Eclipse IDE to program, so my project has these 3 External Jar files loaded into its Build Path.  I hit the Green Arrow to run my program, and it runs great.

Because I'm using Eclipse, I'm  a bit spoiled when it comes to running my programs. I know how to do javac Class.java to build program in command line, but have no idea when it comes to executable jar files with 3 dependencies and a folder called Textures with some images in it.

Could you give me a hand, perhaps in walk-through format so others can benefit and use as a reference? Thanks!
Offline CyanPrime
« Reply #1 - Posted 2010-12-01 02:16:50 »

File->Export->java->runnable jar?

More information on it here: http://lmgtfy.com/?q=eclipse+runnable+jar+lwjgl
Offline ryanm

Senior Devvie


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #2 - Posted 2010-12-01 08:23:46 »

I like to use ant to generate distributable jars - eclipse can do it, but the process is a bit laborious.
I use the GenJar task. It examines class dependencies and only pulls in the classes that you are actually using. It can also fold in entire library jars so you're left with one self-contained jar. You'll still have to have to distribute the natives separately though.

Check out an example build.xml here. It compiles few other eclipse projects into a build directory and then points genjar at it. The "fatjar" task pulls in the lwjgl jars and produces a single executable jar, the "jar" task creates a webstart-ready jar that doesn't include libraries - they will be handled by webstart.

GenJar gotcha: It is a lying, duplicitous cur. If it encounters problems when resolving class dependencies, it complains that it can't find the entry point class where you told it to start the analysis. This causes enormously annoying but-it's-right-bloody-there! confusion. Run ant with the "-d" flag to see where it is actually having problems.

On a side note: I wouldn't mind at all if links to lmgtfy.com were automatically filtered out by the forum.The combination of a miniscule amount of actual help and a massive wedge of passive-aggresive you're-so-thick implication is entirely odious.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Ninja


Medals: 55



« Reply #3 - Posted 2010-12-01 08:59:35 »

File->Export->java->runnable jar?

More information on it here: http://lmgtfy.com/?q=eclipse+runnable+jar+lwjgl

You should have checked the google results. It's not so easy, since you have to handle the native libraries, too, which usually involves writing some fancy wrapper to unpack them to disk temporarily and hand the location over to the java.library.path system property...

Mathias - I Know What [you] Did Last Summer!
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #4 - Posted 2010-12-01 10:00:14 »

You should have checked the google results. It's not so easy, since you have to handle the native libraries, too, which usually involves writing some fancy wrapper to unpack them to disk temporarily and hand the location over to the java.library.path system property...

And since I'm feeling helpful, here's the code from Tectonicus that does exactly that:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
   private void unpackLwjgl()
   {
      String[] files =
      {
         "jinput-dx8_64.dll",
         "jinput-dx8.dll",
         "jinput-raw_64.dll",
         "jinput-raw.dll",
         "libjinput-linux.so",
         "libjinput-linux64.so",
         "libjinput-osx.jnilib",
         "liblwjgl.jnilib",
         "liblwjgl.so",
         "liblwjgl64.so",
         "libopenal.so",
         "libopenal64.so",
         "lwjgl.dll",
         "lwjgl64.dll",
         "openal.dylib",
         "OpenAL32.dll",
         "OpenAL64.dll"
      };
     
      File cacheDir = new File(System.getProperty("user.home"), ".tectonicus/native");
      cacheDir.mkdirs();
      for (String f : files)
      {
         File outFile = new File(cacheDir, f);
         FileUtils.extractResource("Native/"+f, outFile);
      }
     
      String nativePath = cacheDir.getAbsolutePath();
      System.setProperty("org.lwjgl.librarypath", nativePath);
      System.setProperty("net.java.games.input.librarypath", nativePath);
   }

   public static void extractResource(String resource, File outputFile)
   {
      try
      {
         if (outputFile.exists())
            outputFile.delete();
         
         InputStream mcmapIn = TectonicusApp.class.getClassLoader().getResourceAsStream(resource);
         OutputStream out = new FileOutputStream(outputFile);
         
         byte[] buffer = new byte[1024];
         while (true)
         {
            int count = mcmapIn.read(buffer);
            if (count == -1)
               break;
            out.write(buffer, 0, count);
         }
         
         out.close();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }


[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline philfrei
« Reply #5 - Posted 2010-12-02 02:34:27 »

Are you asking how to make an executable JAR using Eclipse, where the complication is the inclusion of the external libraries?
These guys are great:
http://www.eclipse.org/forums/
The folks at the "Newcomers" area, especially Russell Bateman, have been tremendously helpful.

When I do an File->Export, I choose "Jar File" as a destination instead of "Runnable Jar File". The last page: "JAR manifest specification" lets you indicate the application entry point that will run when you click on the JAR file. Thus, you have an executable JAR. The option on "Runnable Jar File" frankly mystifies me. (Not difficult to do. Smiley) One has to select a "launch configuration"?! I have not worked with such objects. And there seems to be no need since simple JAR exports have worked fine for me so far.

One gotcha I run into is that one should double-check the tree on "JAR File Specifications"(second page of export). Expand it completely and make sure all the packages needed are checked, including clicking on the constituent packages to make sure all the class files in them are also checked. (If your cursor is on a given class file when you click export, the default might be to only export that single class file.)

Sounds like you may already know about Properties->JAVA BUILD PATH->Libraries. When I do a WAR export, I have to make sure all the needed libraries are ALSO included in Properties->Deployment Assembly. Seems like needless duplication to me, to have to specify libraries in two places. But the folks at Eclipse have their reasons, I'm sure.

My apologies in advance if this answer is at too basic a level. (A risk when a nOOb attempts to answer  a topic.)

"It's after the end of the world! Don't you know that yet?"
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (105 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!