Large project in JBuilder 2007... How do I create an executable JAR?

First, I've googled quite a bit and keep getting thiings about "Jbuilder Application Wizard", etc... Well, I don't see any "wizard" menu in the version of JBuilder I'm using!

I'm using JBuilder 2007 Enterprise edition, however it's a trial version apparently. I'm not sure if that matters, and perhaps the functionality was taken out with the trial version..

Anyway, the issue is that I have a multi class (with one main function) program that I want to run (it's a command line based application) as an executable JAR file. The program uses LOTS of include statements including quite a few custom libraries ("external JARs") that I had to import.

Basically I want the application to do exactly what it does now when I hit the ol' "RUN" button. Except I want to be able to run it from a batch file with "java -jar (or whatever) myProgram".

Anybody have any experience with this type of thing?

[931 byte] By [shoelessonea] at [2007-11-27 8:34:33]
# 1
I don't know JBuilder, but JAR files can be created on the command line using the jar.exe tool: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
Hippolytea at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 2
In 2005 its File->NewSelect 'Archive' in the treeThen select 'Application'There is an option there for 'Executable Jar' but I have never gotten that to work right, I think 'Application' will get you what you want.
robtafta at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 3

Well, 2007 is basically Eclipse (or so I'm told. This is my first application in like a year, and my first JAVA application in like 2 :().

Anyway, I've exported a jav and called it "testing.jar", but when I open it with winzip it does not contain any of the libraries that it is dependent on... it DOES include a .classpath file that tells the location of the require libraries, but I'll be running this on a computer w/o the libraries, so I want the jar to include everything required that isn't standard java.

shoelessonea at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 4

What you usually do (again, JBuilder magic aside) is to deploy your executable jar with the library jars it needs. You don't nest jars or unzip them and create an oober jar.

In your executable jar's manifest will be a classpath entry, that can have the relative paths to the other jars.

Hippolytea at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 5
Usually JBuilder defaults to the ooberjar, merging all needed libraries into one jar. It is usually just one checkbox during the wizard to not include dependancies.
robtafta at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 6

OK, here's what I've got:

I've got a jar file that contains:

1. a folder "importQD"

2. a folder called META-INF

3. a .classpath file

4. a .project file

Inside the importQD folder are my three .class files that are the classes I created myself.

Inside the META-INF folder is the MANIFEST.MF file which looks like:

Manifest-Version: 1.0

Main-Class: importQD.ImportQD

Inside the .classpath file we have:

<?xml version="1.0" encoding="UTF-8"?>

<classpath>

<classpathentry kind="src" path=""/>

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\CMUploadInterface83.jar"/>

<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\DBCon.jar"/>

<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\SENAeMail.jar"/>

<classpathentry kind="lib" path="C:\Programs\CMQualityDocumentImport\SENAFileHandler.jar"/>

<classpathentry kind="output" path=""/>

</classpath>

NOTE: All of the paths point at the .jar files as they are located on the machine the final version will be running on.

Inside the .project file we have:

<?xml version="1.0" encoding="UTF-8"?>

<projectDescription>

<name>importOldQD</name>

<comment></comment>

<projects>

</projects>

<buildSpec>

<buildCommand>

<name>org.eclipse.jdt.core.javabuilder</name>

<arguments>

</arguments>

</buildCommand>

</buildSpec>

<natures>

<nature>org.eclipse.jdt.core.javanature</nature>

</natures>

</projectDescription>

Now, it would make sense to me that this should be all good to go, and that I should be able to run this via a command line now. When I try

java -jar importQD.jar

I get a ton of various errors such as "Exception in thread "main" java.lang.UnsupportedClassVersionError: importQD/importQD (unsupported major.minor version 49.0)+ a nice stack trace with a bunch of java.lang and java.net references.

What am I doing wrong?

shoelessonea at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 7
That error has to do with what version of the JDK you are using. I think it happens when you use a library was built with one version of the JDK, and your JDK is an older version.If you have a .project file, it really does sound like eclipse. I wonder why they switched.
robtafta at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 8

> I wonder why they switched.

No idea, but it's strange - of the three different IDEs i've used at work, ALL three of them are based on eclipse (WorkShop for weblogic, JBuilder, and another)

Anyway, any other help?

Should what I'm doing work?

Anybody confirm that I just need to install a newer versio of the JDK (it's a networked computer so that isn't as easy as it sounds)?

Thanks!

shoelessonea at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 9
Did you figure out how to Jar things in 2007? Eclipse doesn't come with this most basic neccessity, you have to download this additional plugin 'fatjar' to get that. Seems like a step backwards for them.
robtafta at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 10

Yes I did actually, thank you!

AND, I recompiled my code with the 1.4 version of Java instead of 5.0 or whatever, and all is well - ALMOST

Now, in a seperate (but yet related) issue, I think I'm having problems importing the custom "libraries" that I need to use..

Here is the basic setup:

I have a class called "FileHandler" that I create an instance of in my main class. In the "FileHandler" code I have an import statement:

import NAFileHandler.*;

Then, in my classpath I have set:

<classpathentry kind="lib" path="C:/Programs/CMQualityDocumentImport/NAFileHandler.jar"/>

That of course being the location of the NAFileHandler.jar file on the system the code will be run on.

BUT, when I run the jar file with java -jar importQDtoCM.jar

I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: NAFileHandler/NAFileHander ...........

And then a stacktrace that goes back to the location I tried to make a new instance of NAFileHandler.

Any chance you might have any ideas as to what's going on? (Not that you haven't earned your valuable Star Points or whatever ;)

edit: I mean I'm pretty sure it's not finding the NAFileHandler files as it should.. but why? My classpaths and things seem correct?

Message was edited by:

shoelessone

shoelessonea at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...
# 11
just a guess, but what is in that jarfile? Open it with 7zip or winzip and take a peek, see if that class is really in there. Other than that, I can't think of anything, typo somewhere, idk.
robtafta at 2007-7-12 20:30:50 > top of Java-index,Java Essentials,Java Programming...