netbeans doesn't create lib directory under dist

J

jadrian

I'm trying to use netbeans 5.5 to create an executable on windows.
The app depends on on ibm db2 jars as well as the log4j jar. I can
build and run the app from the ide but when I try to run it standalone
it complains that it can't load the log4j Logger. Specifically when
it builds it doesn't create a lib directory under dist.

I've gone through the documentation; it says you need to specify a
main class. I've done that, I have the libraries listed under the
Libraries directory in the ide and tried about a hundred things but no
luck.

Any thoughts?

Thanks
 
L

Lew

I'm trying to use netbeans 5.5 to create an executable on windows.
The app depends on on ibm db2 jars as well as the log4j jar. I can
build and run the app from the ide but when I try to run it standalone
it complains that it can't load the log4j Logger. Specifically when
it builds it doesn't create a lib directory under dist.

I've gone through the documentation; it says you need to specify a
main class. I've done that, I have the libraries listed under the
Libraries directory in the ide and tried about a hundred things but no
luck.

Leaving aside the "executable on windows [sic]" question, even a "lib
directory under dist" isn't an automatic way to include libraries. The
distribution JAR must include a class path in its manifest, or the "java"
command that executes the main class must specify a class path that includes
your library JARs.
 
M

Mark Space

I'm trying to use netbeans 5.5 to create an executable on windows.
The app depends on on ibm db2 jars as well as the log4j jar. I can
build and run the app from the ide but when I try to run it standalone
it complains that it can't load the log4j Logger. Specifically when


Just curious: is this a web application? I.e., are you actually
distributing a .jar, or a .war?
 
J

jadrian

Just curious: is this a web application? I.e., are you actually
distributing a .jar, or a .war?

Not a web app, just a .jar.

It's not complicated and I originally coded it on a unix box without
any ide. Under those circumstances I could just keep appending jars
and directories to my CLASSPATH environment variable. That's why I
said "... create an executable on windows." It works fine on unix but
NetBeans ties pieces together according to a different set of rules.
I think the rules are well understood by people who are used to using
an ide but not if you're used to hand-cobbling it together.

The log4j jar file is on the environment CLASSPATH variable in the
command window I run the packaged jar file in so I assume that
NetBeans communicates the CLASSPATH some other way. NetBeans
documentation says that it will create a lib directory under the dist
directory but it doesn't. I tried manually putting in the classpath
in the manifest file but no luck.

I think the solution is in front of my nose but I can't see it.
 
L

Lew

Not a web app, just a .jar.

It's not complicated and I originally coded it on a unix box without
any ide. Under those circumstances I could just keep appending jars
and directories to my CLASSPATH environment variable. That's why I
said "... create an executable on windows." It works fine on unix but
NetBeans ties pieces together according to a different set of rules.
I think the rules are well understood by people who are used to using
an ide but not if you're used to hand-cobbling it together.

The log4j jar file is on the environment CLASSPATH variable in the
command window I run the packaged jar file in so I assume that
NetBeans communicates the CLASSPATH some other way. NetBeans
documentation says that it will create a lib directory under the dist
directory but it doesn't. I tried manually putting in the classpath
in the manifest file but no luck.

How exactly are you running the program? If it's via "java -jar your.jar"
then the classpath is ignored, and only the Class-Path: in the manifest prevails.

What is your manifest's Class-Path: entry?

You refer to these things, but you do not reveal them. How can we help you?
 
M

mark.donaghue

How exactly are you running the program? If it's via "java -jar your.jar"
then the classpath is ignored, and only the Class-Path: in the manifest prevails.

What is your manifest's Class-Path: entry?

You refer to these things, but you do not reveal them. How can we help you?

Does your netbeans project by any chance have an ant script
(build.xml) associated with it? If so, check for your classpath
there.
 
J

jadrian

How exactly are you running the program? If it's via "java -jar your.jar"
then the classpath is ignored, and only the Class-Path: in the manifest prevails.

What is your manifest's Class-Path: entry?

You refer to these things, but you do not reveal them. How can we help you?

Sorry about that, the manifest file (now):

Manifest-Version: 1.0

Name: ConnMetrics
Main-Class: ConnMetrics
Class-Path: C:\projects\CONNSTAT\log4j-1.2.15.jar C:\projects\CONNSTAT
\connMetric\ConnMetrics

.... and, at some point, netbeans DID create a lib directory, possibly
after I added the Class-Path: line after your last response?

Now I have another path problem. It can't find the jdbc.properties
file. Last Friday I ran this from netbeans and it and two other
properties files were found. Any thoughts on how it finds resource
bundles?

I'm developing it under C:\projects\CONNSTAT\connMetric\ConnMetrics
directory, which is both the working directory and the project folder.

I'm trying to run it under C:\projects\CONNSTAT\testRun\dist which has
the ConnMetrics.jar and a lib\ subdirectory.

I put the jdbc.properties file in C:\projects\CONNSTAT\testRun\dist
just to see if it would find it but it didn't.

Generally I'd like some understanding of how a jar file created in a
dist\ directory in netbeans looks for jars, classes, resource bundles,
etc.

If you need some configuration information like the manifest please
let me know. I just don't want to clutter the post with a lot of
useless stuff and I have to be careful to not put out anything that
could be construed as confidential corporate data.

Thanks,

Jeff
 
L

Lew

I think the solution is in front of my nose but I can't see it.

I'm running NetBeans 6 (beta) (with Java 6u3) but I tried the process anyway;
it really hasn't changed.

First, I reviewed NetBeans's documentation on how to deploy an application.
<http://www.netbeans.org/kb/articles/javase-deploy.html>
in particular,
<http://www.netbeans.org/kb/articles/javase-deploy.html#Exercise_1>

To a project called "testit", I added the log4j library as a NetBeans library
(menu "_T_ools / _L_ibraries"). Did a project "Clean and Build". This
created a dist/ subdirectory within my project directory.
$ ls dist
lib README.TXT testit.jar
$ ls dist/lib
log4j-1.2.14.jar

I think the key was the "Clean" part of "Clean and Build". Doing just a
"Build" (it was a pre-existing project) didn't create either JAR file.

Bear in mind that these JARs must deploy together, in the same relative
directory relationship.

Then I examined testit.jar.
$ cd dist
$ jar tf testit.jar
META-INF/
META-INF/MANIFEST.MF
testit/
log4j.properties
testit/PolyMatrix.class

Contents of META-INF/MANIFEST.MF:
$ jar xf testit.jar META-INF/MANIFEST.MF
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.6.0_03-b05 (Sun Microsystems Inc.)
Main-Class: testit.PolyMatrix
Class-Path: lib/log4j-1.2.14.jar
X-COMMENT: Main-Class will be added automatically by build

Runs great:
$ java -jar testit.jar

2007-10-08 17:53:55,708 ERROR testit.PolyMatrix : Didn't initialize entire matrix [main ]
java.lang.NullPointerException
at testit.PolyMatrix.main(PolyMatrix.java:81)

I have no CLASSPATH envar defined, not that it would matter.

Code snippet to show the log4j call:
try
{
mat [0] [0] [0] = BigInteger.ZERO; // line 81
}
catch ( NullPointerException exc )
{
logger.error( "Didn't initialize entire matrix", exc );
}

Only the outer dimensions of 'mat' were initialized, causing a reference to
the third dimension to throw the NPE. The NPE was intentional, to show use of
log4j.
 
L

Lew

... the manifest file (now):

Manifest-Version: 1.0

Name: ConnMetrics
Main-Class: ConnMetrics
Class-Path: C:\projects\CONNSTAT\log4j-1.2.15.jar C:\projects\CONNSTAT
\connMetric\ConnMetrics

This is not a workable Class-Path: entry. You should use relative paths.
This is done automatically by NetBeans in its build. Manifest paths use
forward slashes.

Is the log4j JAR actually in that directory you specify?

Will it be in that same directory everywhere your app is deployed?

What is the purpose for the folder that you list ("**/ConnMetrics")?
Generally I'd like some understanding of how a jar [sic] file created in a
dist\ [sic] directory in netbeans [sic] looks for jars, classes, resource bundles,
etc.

Have you studied everything on
<http://java.sun.com/javase/6/docs/technotes/guides/jar/index.html>
?

Reading the instructions is an awfully useful exercise.

BTW, resource bundles are found through the class path.
If you need some configuration information like the manifest please
let me know. I just don't want to clutter the post with a lot of
useless stuff and I have to be careful to not put out anything that
could be construed as confidential corporate data.

Since your problem is in the manifest, it's hardly "useless stuff".
 
J

jadrian

Finally got it.

Thanks to Lew and the two Marks.

The fundamental issue has to do with how to tell NetBeans to include
libraries for distribution. Lew is correct that that is derived from
META-INF/MANIFEST.MF which is bundled in the distributable jar file
but NetBeans is supposed to build that and it was not doing so.

The problem was that I was trying to add the required jar files by
right-clicking the project node and selecting "Properties", which
brings up the project properties window. In the properties window
there is a Libraries selection which brings up a tabbed window. The
tabs are "Compile", "Run", "Compile Tests" and "Run Tests". For each
of those there are buttons to "Add Project...", "Add Library", and
"Add JAR/Folder" and it was here that I made my mistake by using the
"Add JAR/Folder" option to try to bring the external jar files into
the project.

I should have clicked the "Add Library" button (or, from the Projects
pane, right-clicked "Libraries" and selected "Add Library"). The
window that comes up for "Add Library" lists standard libraries not
part of the JDK (this is taken from the site Lew recommended
http://www.netbeans.org/kb/articles/javase-deploy.html). In this
window you can choose "Manage Libraries..." which brings up a window
that has a button "New Library". Create a new library, say,
"MyLibrary", click "Add JAR/Folder" and include the jar files you
need.

For the resource bundles I just included them in the "src" directory.
I first deleted the existing project and re-created it as described
above and the dist/lib directory was created, the META-INF/MANIFEST.MF
file it created had everything in it that was needed and the app ran
fine when the dist directory was moved elsewhere.

You raised many very good points, Lew, which I will keep around for
future reference. In this case the issue primarily was my lack of
familiarity with the NetBeans ide aggravated by the many gaps in my
knowledge of the java programming paradigm.

Thanks again for everyone's help.

Jeff
 
R

Ron

I had the exact same problem. When I first started working with
Netbeans, my lib directory in the dist directory was created and
populated correctly. I did not have to add my libraries with the
library manager. I just added them as Netbeans projects. Everything
was great.

But then it stopped creating the lib directory. :(

I tried alot of stuff to get that lib directory back. I double and
triple checked that my project files (everything in nbproject) had not
changed. I tried all the advice in this thread, including adding my
jar files to the libraries governed by the Library Manager. Nothing
worked.

Then I became suspicious that one of the updates applied by Update
Center must have broken this functionality. I re-installed Netbeans
from scratch, loaded my projects and re-built, and now my lib
directory was back!

I will slowly apply the updates one at a time, and see if I can find
the culprit.
 
L

Lew

Ron said:
I had the exact same problem. When I first started working with
Netbeans, my lib directory in the dist directory was created and
populated correctly. I did not have to add my libraries with the
library manager. I just added them as Netbeans projects. Everything
was great.

But then it stopped creating the lib directory. :(

I tried alot of stuff to get that lib directory back. I double and
triple checked that my project files (everything in nbproject) had not
changed. I tried all the advice in this thread, including adding my
jar files to the libraries governed by the Library Manager. Nothing
worked.

Then I became suspicious that one of the updates applied by Update
Center must have broken this functionality. I re-installed Netbeans
from scratch, loaded my projects and re-built, and now my lib
directory was back!

I will slowly apply the updates one at a time, and see if I can find
the culprit.

Please do not top-post. Use trim-and-inline posting.

NetBeans isn't supposed to put a lib directory under dist/. It goes in
build/. dist/ is where the JAR / WAR / EAR files go.
 
N

Nigel Wade

Lew said:
NetBeans isn't supposed to put a lib directory under dist/. It goes in
build/. dist/ is where the JAR / WAR / EAR files go.

The dist/ directory of an application is supposed to be self-contained so that
the contents of dist/ can be packaged and shipped as a single entity. dist/
contains the application jar, and dist/lib any jars on which the main jar
depends. The manifest of the application's jar will include lib/whatever.jar in
the classpath for each dependent jar.
 
L

Lew

Nigel said:
The dist/ directory of an application is supposed to be self-contained so that
the contents of dist/ can be packaged and shipped as a single entity. dist/
contains the application jar, and dist/lib any jars on which the main jar
depends. The manifest of the application's jar will include lib/whatever.jar in
the classpath for each dependent jar.

By golly, you're right. It sure looks like a NetBeans bug to me.

I had gotten so used to web apps that I forgot to double-check application builds.
 
R

Ron

Please do not top-post. Use trim-and-inline posting.

NetBeans isn't supposed to put a lib directory under dist/. It goes in
build/. dist/ is where the JAR / WAR / EAR files go.

Not sure if you have read this page:
http://www.netbeans.org/kb/articles/javase-deploy.html

In it, it says:
"If you have specified any libraries for the project (in addition to
the JDK), a lib folder is created in the dist folder. The libraries
are copied into dist/lib."
 
N

Nigel Wade

Lew said:
By golly, you're right. It sure looks like a NetBeans bug to me.

I had gotten so used to web apps that I forgot to double-check application builds.

It has its advantages and disadvantages. It is convenient that the application
is self-contained and means the application can be easily tested outside of
NetBeans. But if you are building several applications all of which have
similar dependencies then you end up with a huge amount of duplication.
 
S

Sabine Dinis Blochberger

Lew said:
By golly, you're right. It sure looks like a NetBeans bug to me.
No actually, it says if you add a folder (instead of a jar) to a
library, it won't put out your /lib anymore. Says so very
inconspicuously somewhere in the help.

Had the same problem, removing the "just paths" parts (i.e.
"c:\javalibs\bla") from my own created libraries solved it.
 
L

Lew

Sabine said:
No actually, it says if you add a folder (instead of a jar) to a
library, it won't put out your /lib anymore. Says so very
inconspicuously somewhere in the help.

Funny, when I went to duplicate the problem I only added JARs, not folders, to
the libraries and it still failed to generate a lib/.

Unless they are also suppressing lib/ when you add Javadoc and source folders
to the library.
 
R

Ron

Funny, when I went to duplicate the problem I only added JARs, not folders, to
the libraries and it still failed to generate a lib/.

Unless they are also suppressing lib/ when you add Javadoc and source folders
to the library.

I had the same results. No matter how I added the required libraries
(as a project, as a .jar, as a library), it would not put those
dependencies in the lib folder.

If this is not a bug, if this is an intended change to behaviour, can
someone publish the new instructions for producing a distribution for
an application? I could not find any information about this change in
the help or on the web.
 
S

Sabine Dinis Blochberger

Lew said:
Funny, when I went to duplicate the problem I only added JARs, not folders, to
the libraries and it still failed to generate a lib/.

Unless they are also suppressing lib/ when you add Javadoc and source folders
to the library.
Hm, I don't have any with sources added, but with Javadoc paths. In the
Classpath part, only have jar files. And if *any* of your used libraries
contains a path there, the /lib isn't created apparently...

Found the passage in the Netbeans (5.5.1) help:

"Preparing a JAR file for Deployment Outside the IDE

* If you added a folder of classes or resources to the classpath (as
opposed to a JAR file or project), none of the classpath elements are
copied to the dist folder."
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top