Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

netbeans doesn't create lib directory under dist

Thread view: 
jadrian@wi.rr.com - 08 Oct 2007 18:25 GMT
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
Lew - 08 Oct 2007 18:34 GMT
> 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
[quoted text clipped - 6 lines]
> 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.

Signature

Lew

Mark Space - 08 Oct 2007 20:39 GMT
> 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?
jadrian@wi.rr.com - 08 Oct 2007 21:57 GMT
> jadr...@wi.rr.com wrote:
> > I'm trying to use netbeans 5.5 to create an executable on windows.
[quoted text clipped - 4 lines]
> 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.
Lew - 08 Oct 2007 22:03 GMT
> Not a web app, just a .jar.
>
[quoted text clipped - 12 lines]
> 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?

Signature

Lew

mark.donaghue@gmail.com - 08 Oct 2007 22:25 GMT
> jadr...@wi.rr.com wrote:
> > Not a web app, just a .jar.
[quoted text clipped - 23 lines]
> --
> Lew

Does your netbeans project by any chance have an ant script
(build.xml) associated with it? If so, check for your classpath
there.
jadrian@wi.rr.com - 08 Oct 2007 23:08 GMT
> jadr...@wi.rr.com wrote:
> > Not a web app, just a .jar.
[quoted text clipped - 23 lines]
> --
> Lew

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
Lew - 08 Oct 2007 23:18 GMT
> ... the manifest file (now):
>
[quoted text clipped - 4 lines]
> 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".

Signature

Lew

Lew - 08 Oct 2007 23:10 GMT
> 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
[quoted text clipped - 3 lines]
> log4j.properties
> testit/PolyMatrix.class

Contents of META-INF/MANIFEST.MF:
> $ jar xf testit.jar META-INF/MANIFEST.MF
> $ cat META-INF/MANIFEST.MF
[quoted text clipped - 4 lines]
> 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
>  {
[quoted text clipped - 4 lines]
>    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.

Signature

Lew

jadrian@wi.rr.com - 09 Oct 2007 19:38 GMT
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
Ron - 01 Nov 2007 09:18 GMT
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.

On Oct 8, 1:25 pm, jadr...@wi.rr.com wrote:
> I'm trying to usenetbeans5.5 to create an executable on windows.
> The app depends on on ibm db2 jars as  well as the log4j jar.  I can
[quoted text clipped - 10 lines]
>
> Thanks
Lew - 01 Nov 2007 13:59 GMT
> I had the exact same problem.  When I first started working with
> Netbeans, my lib directory in the dist directory was created and
[quoted text clipped - 17 lines]
> 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.

Signature

Lew

Nigel Wade - 01 Nov 2007 14:17 GMT
> 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.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Lew - 01 Nov 2007 14:28 GMT
Lew wrote:

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

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.

Signature

Lew

Nigel Wade - 01 Nov 2007 17:25 GMT
> Lew wrote:
>>
[quoted text clipped - 10 lines]
>
> 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.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Sabine Dinis Blochberger - 05 Nov 2007 12:12 GMT
> Lew wrote:
> >
[quoted text clipped - 8 lines]
>
> 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.

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

Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

Lew - 05 Nov 2007 14:51 GMT
>> Lew wrote:
>>>> NetBeans isn't supposed to put a lib directory under dist/.  It goes in
[quoted text clipped - 9 lines]
> 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.

Signature

Lew

Ron - 05 Nov 2007 16:00 GMT
> >> Lew wrote:
> >>>> NetBeans isn't supposed to put a lib directory under dist/.  It goes in
[quoted text clipped - 20 lines]
>
> - Show quoted text -

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.
Sabine Dinis Blochberger - 06 Nov 2007 10:31 GMT
> >> Lew wrote:
> >>>> NetBeans isn't supposed to put a lib directory under dist/.  It goes in
[quoted text clipped - 15 lines]
> 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."
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

Lew - 06 Nov 2007 14:39 GMT
Lew wrote:
>> 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/.

> 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
[quoted text clipped - 7 lines]
> opposed to a JAR file or project), none of the classpath elements are
> copied to the dist folder."

Lew wrote:
>> 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/.

Signature

Lew

Ron - 01 Nov 2007 14:46 GMT
> > I had the exact same problem.  When I first started working with
> > Netbeans, my lib directory in the dist directory was created and
[quoted text clipped - 27 lines]
>
> - Show quoted text -

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."


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.