Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
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  
  Library jar into executable jar  (Read 2876 times)
0 Members and 1 Guest are viewing this topic.
Offline Juriy

Junior Devvie





« Posted 2006-05-05 15:33:02 »

Hi guys!

I'm trying to develop a nice game resource manager for my game and I'm having a little problem:

I'm using jdom to work with xml files and I want to include it to the executable jar somehow. The problem is - whatever I'm trying to do I get a
1  
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/JDOMException


Actually I cannot launch my editor from jar (no way!).

I've tried something like this:

1  
2  
3  
4  
5  
C:\apps\eclipse\workspace\MRM\final>java -cp c:\apps\jars\jdom.jar -jar MRM.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/JDOMException

C:\apps\eclipse\workspace\MRM\final>java -cp c:\apps\jars\jdom.jar;. -jar MRM.ja
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/JDOMException


There is no problem launching unpacked version of this soft...

Actually there is a solution: copy all needed library classes to the root of the executable jar. But this solution is not very good.

Plz help.

http://voituk.kiev.ua - java tutorials, tips and tricks (Russian)
Offline theKman

Senior Newbie




Java games rock!


« Reply #1 - Posted 2006-05-05 18:23:07 »

You must edit your jar's manifest and add the line Class-Path: path-tojdom
Offline Juriy

Junior Devvie





« Reply #2 - Posted 2006-05-06 12:35:27 »

I've tried to add Class-Path to jar... Still it doesn't work. My manifest file looks like that:

1  
2  
3  
Manifest-Version: 1.0
Main-Class: ua.com.attacksoftware.mrm.MRM
Class-Path: c:\apps\jars\jdom.jar


By the way what class path should I write to manifest if a library jar is nested inside the executable jar?

Does Java support nested jars at all? Is it possible to create a single jar if my app uses third-party libraries?

http://voituk.kiev.ua - java tutorials, tips and tricks (Russian)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Devvie


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #3 - Posted 2006-05-06 14:21:40 »

Huzzah!

Another opportunity to pimp GenJar. It makes all of this jar-generation malarkey completely trivial.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #4 - Posted 2006-05-06 15:39:54 »

Why not do something like this?
1  
java -cp jdom.jar;MRM.jar your.MainClass


IIRC, the -jar parameter overrides -cp which would explain why jdom can't be found

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #5 - Posted 2006-05-06 15:52:33 »

Why not do something like this?
1  
java -cp jdom.jar;MRM.jar your.MainClass


IIRC, the -jar parameter overrides -cp which would explain why jdom can't be found

Yep. It's braindead, and has confused many many people over the years - but it IS in Sun's docs; classpath is *completely ignored* whenever you use -jar.

malloc will be first against the wall when the revolution comes...
Offline Juriy

Junior Devvie





« Reply #6 - Posted 2006-05-06 16:30:00 »

Quote
IIRC, the -jar parameter overrides -cp which would explain why jdom can't be found

Great! Thnx, that is really great info!

Quote
Why not do something like this?

1  
java -cp jdom.jar;MRM.jar your.MainClass

All is simple... I'm writing this software for non-tech-guys. They are just game balance testers and everything they know about Java is that it is a nice coffee... Becasue of that I want to make installation and run processes as easy as possible.

http://voituk.kiev.ua - java tutorials, tips and tricks (Russian)
Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2006-05-10 04:25:04 »

Why not do something like this?
1  
java -cp jdom.jar;MRM.jar your.MainClass


IIRC, the -jar parameter overrides -cp which would explain why jdom can't be found

Yep. It's braindead, and has confused many many people over the years - but it IS in Sun's docs; classpath is *completely ignored* whenever you use -jar.

As confusing as it is, it really IS logical if you thin kabout it.

-classpath is defined as just repalcing the environment CLASSPATH

-jar is made for app packages that are all self contained where you DON'T want the environment screwing with or changing how they execute

That coudl be even more confusing.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Anon666

Junior Devvie




aka Abuse/AbU5e/TehJumpingJawa


« Reply #8 - Posted 2006-05-10 21:15:49 »

If -jar and -cp are mutually exclusive, then it is an error if a command-line invocation includes both.

As such, the java executable should throw an error indicating this.
It would resolve all confusion in the matter.

Perhaps someone could put forward an RFC for this?
Offline Sequalit

Junior Devvie





« Reply #9 - Posted 2006-05-11 23:21:25 »

one thing you could do is when you figure out how to launch correctly at command line, create a batch file they can double click, or make and executablet hat does that (however you do that lol) thats what eclipse and azureus and other java made applications work.

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Juriy

Junior Devvie





« Reply #10 - Posted 2006-05-12 09:21:31 »

Quote
one thing you could do is when you figure out how to launch correctly at command line, create a batch file they can double click...

Actually this is the the best solution I've found so far.

Quote
or make and executablet hat does that

Can you explaine in a bit more detail? Is there a specialized tool for doing that?

http://voituk.kiev.ua - java tutorials, tips and tricks (Russian)
Offline Sequalit

Junior Devvie





« Reply #11 - Posted 2006-05-12 18:01:06 »

Can you explaine in a bit more detail? Is there a specialized tool for doing that?

Okay, found a way to go about converting your batch file into an executable

http://www.abyssmedia.com/quickbfc/index.shtml

theres to link to a program that does it (dunno if it cost money) if it does, just do a google search for "batch compilers"

good luck =D

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Offline purpleguitar

Junior Devvie





« Reply #12 - Posted 2006-05-26 14:19:28 »

What I have done to make executable jars is write a little ant script that will expand my library jars into a tmp folder, then make an executable jar, then wipe out the tmp directory.  Using an ant build script from within Eclipse, it looks a bit like this:

<project default="makejar">

<!-- The name of the generated jar file -->
   <property name="my.jar" location="${basedir}/WhateverYouLike.jar"/>

<!-- The name for a temporary directory -->
   <property name="tmpdir" location="${basedir}/__tmp__"/>

<!-- The JAR files that must be put into the executable jar -->
   <property name="lib" location="${basedir}/lib"/>
<!-- The manifest file for the output jar -->
   <property name="manifest" location="${basedir}/MANIFEST.MF"/>

   <!-- The non-jar resources to be put into the executable jar -->
   <property name="classes" location="${basedir}/classes"/>
   <property name="resources" location="${basedir}/resources"/>

<target name="makejar">

<mkdir dir="${tmpdir}"/>

 <!-- Unzip all the jars into the temporary directory -->
     <unjar dest="${tmpdir}">
       <fileset dir="${lib}">
         <include name="*.jar"/>
       </fileset>
    </unjar>
   
      <!-- Create a new JAR file -->
      <jar destfile="${my.jar}" manifest="${manifest}">
         <fileset dir="${tmpdir}" excludes="**/META-INF/**"/>
         <fileset dir="${classes}"/>
         <fileset dir="${resources}"/>
      </jar>
      
      <!-- Remove the temporary files -->
      <delete dir="${tmpdir}"/>
   </target>
   
</project>
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #13 - Posted 2006-05-26 16:56:18 »

If -jar and -cp are mutually exclusive, then it is an error if a command-line invocation includes both.

Sorry, Jeff, but he's right Smiley.

I'm not referring to "the original thinking behind the possibility of architecting the back-end the way it was" as braindead - but making the most important and most used tool in the java platform so counter-intuitive (and, techincally, wrong as per above) from a user perspective.

malloc will be first against the wall when the revolution comes...
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.

trollwarrior1 (27 views)
2014-11-22 12:13:56

xFryIx (69 views)
2014-11-13 12:34:49

digdugdiggy (48 views)
2014-11-12 21:11:50

digdugdiggy (42 views)
2014-11-12 21:10:15

digdugdiggy (36 views)
2014-11-12 21:09:33

kovacsa (60 views)
2014-11-07 19:57:14

TehJavaDev (64 views)
2014-11-03 22:04:50

BurntPizza (62 views)
2014-11-03 18:54:52

moogie (77 views)
2014-11-03 06:22:04

CopyableCougar4 (77 views)
2014-11-01 23:36:41
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!