Build an installable package with NetBeans

B

bruce

Can I use NetBeans to build an installable package? If so, how? If
not, what should use?

Thanks..

Bruce
 
B

bruce

Can I use NetBeans to build an installable package? If so, how?  If
not, what should use?

Thanks..

Bruce

I tried to run the .jar file from the command line and got an error

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

What do I need to do to link the jdbc driver to my code?

Thanks...


Bruce
 
J

John B. Matthews

bruce said:
I tried to run the .jar file from the command line and got an error

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

What do I need to do to link the jdbc driver to my code?

The driver needs to be on the class path, specified either via the
command line or in the JAR's manifest. When you build the project,
NetBeans puts everything in a folder named "dist" with a README.TXT
that says, in part:

"When you build an Java application project that has a main class, the
IDE automatically copies all of the JAR files on the projects classpath
to your projects dist/lib folder. The IDE also adds each of the JAR
files to the Class-Path element in the application JAR files manifest
file (MANIFEST.MF)."
 
B

bruce

The driver needs to be on the class path, specified either via the
command line or in the JAR's manifest. When you build the project,
NetBeans puts everything in a folder named "dist" with a README.TXT
that says, in part:

"When you build an Java application project that has a main class, the
IDE automatically copies all of the JAR files on the projects classpath
to your projects dist/lib folder. The IDE also adds each of the JAR
files to the Class-Path element in the application JAR files manifest
file (MANIFEST.MF)."

Yah, I read that information. My MANIFEST.MF is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_16-b01 (Sun Microsystems Inc.)
Main-Class: CensusRecords.Census1930
Class-Path:
X-COMMENT: Main-Class will be added automatically by build

Do I have to add something to the MANIFEST.MF file? If it's the class
path, how do I find out what it is?

Thanks for the response..

Bruce
 
J

John B. Matthews

bruce said:
Yah, I read that information. My MANIFEST.MF is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_16-b01 (Sun Microsystems Inc.)
Main-Class: CensusRecords.Census1930
Class-Path:
X-COMMENT: Main-Class will be added automatically by build

Do I have to add something to the MANIFEST.MF file? If it's the class
path, how do I find out what it is?

It looks like you modified it from the default:

$ cat manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

You can use this utility to see your manifest, as built:

<http://sites.google.com/site/drjohnbmatthews/manifesto>
 
B

bruce

It looks like you modified it from the default:

$ cat manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

You can use this utility to see your manifest, as built:

<http://sites.google.com/site/drjohnbmatthews/manifesto>

I "Don't" think I modified my MANIFEST.ME. All I did was load it from
the file list, select All, and copy/paste into my note.

Anyhow, I can now run my application from the command line. I added
mysql-connector-java-5.1.13 to my system CLASSPATH.

Which brings to mind a question! Should I leave mysql-connector-
java-5.1.13 in my system CLASSPATH or move it to my Java CLASSPATH?

Thanks...

Bruce
 
J

John B. Matthews

bruce said:
I "Don't" think I modified my MANIFEST.ME. All I did was load it from
the file list, select All, and copy/paste into my note.

Try replacing it with the default, and see if NetBeans handles it
correctly.

Turning again to the relevant SSCCE, <http://pastebin.com/nWHciPh0>,
here is the default manifest for a freshly created project:

$ cat manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

Build the project:

$ ant jar
....
BUILD SUCCESSFUL
Total time: 0 seconds

As built, the manifest lists the the required JARs:

$ manifest dist/Temp.jar
Manifest: dist/Temp.jar
Ant-Version: Apache Ant 1.7.1
X-COMMENT: Main-Class will be added automatically by build
Class-Path: lib/swing-layout-1.0.4.jar lib/AbsoluteLayout.jar
Manifest-Version: 1.0
Created-By: 1.5.0_24-149 (Apple Inc.)
Main-Class: temp.Main

If your driver JAR is known to NetBeans, it should be among those listed
after Class-Path.
Anyhow, I can now run my application from the command line. I added
mysql-connector-java-5.1.13 to my system CLASSPATH.

Which brings to mind a question! Should I leave mysql-connector-
java-5.1.13 in my system CLASSPATH or move it to my Java CLASSPATH?

I've put JARs in one of the java.ext.dirs in the past, but it inevitably
leads to problems. It's best to specify the class path either via the
command line or in the JAR's manifest.
 
L

Lew

I've put JARs in one of the java.ext.dirs in the past, but it inevitably
leads to problems. It's best to specify the class path either via the
command line or in the JAR's manifest.

Classpath management is one of the arcane sciences. It is well worth the time
to read up on it. Links and summary:

<http://download.oracle.com/javase/6/docs/technotes/tools/solaris/java.html#options>
"-jar ... When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored."

<http://download.oracle.com/javase/tutorial/deployment/jar/downman.html>
<http://download.oracle.com/javase/tutorial/deployment/jar/manifestindex.html>
<http://download.oracle.com/javase/6/docs/technotes/tools/solaris/jar.html>

<http://download.oracle.com/javase/tutorial/essential/environment/paths.html>

java.ext.dirs serve a special, special purpose. An extension is not a simple
classpath element. It transforms the Java platform itself into a
special-purpose environment. It applies to every regular application. (I'm
pretty sure the "-jar" classpath blockage applies to extension directories,
however.) In effect, extensions become part of Java itself for that platform.

Regular classpath elements are nodes for conventional libraries. Regular
classpaths are those specified in the CLASSPATH envar, tools' "-classpath" and
"-cp" options, and JAR manifests when run under "-jar".

CLASSPATH, like extensions, applies to all non-"-jar" executions, regardless.
It's convenient when you really do want to specify common library search
paths for all Java things at a level less than extending the platform. I
consider this need rare.

Classpath tool options are best for running Java things under the control of
your local preferences. A command "java -cp <whatever> ..." gives the
invoking Java control of the classpath. It's far more flexible than the
CLASSPATH envar.

JAR manifest "Class-Path:" serves the primary purpose of a JAR - to provide a
self-contained delivery mechanism for a library or application. It overrides
the invoking "java" classpath to give the JAR itself command of the classpath.

The catch to JAR manifest "Class-Path:" is that the referenced library JARs
have to live outside the commanding JAR in the host filesystem, not within the
JAR itself. A full JAR-based deployment would be something like a ZIP holding
the application JAR and its helper JARs in relative paths to the main one.
The user unpacks the ZIP into a target directory on their system and voilà.

That's downward-relative. Use of "../" in JAR paths is ill-advised. Same
directory or relative "lib/" are two suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top