Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > netbeans doesn't create lib directory under dist

Reply
Thread Tools

netbeans doesn't create lib directory under dist

 
 
jadrian@wi.rr.com
Guest
Posts: n/a
 
      10-08-2007
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

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      10-08-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.

--
Lew
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      10-08-2007
(E-Mail Removed) wrote:
> 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?
 
Reply With Quote
 
jadrian@wi.rr.com
Guest
Posts: n/a
 
      10-08-2007
On Oct 8, 2:39 pm, Mark Space <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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?


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.

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-08-2007
(E-Mail Removed) wrote:
> 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?

--
Lew
 
Reply With Quote
 
mark.donaghue@gmail.com
Guest
Posts: n/a
 
      10-08-2007
On Oct 8, 5:03 pm, Lew <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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?
>
> --
> Lew


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


 
Reply With Quote
 
jadrian@wi.rr.com
Guest
Posts: n/a
 
      10-08-2007
On Oct 8, 4:03 pm, Lew <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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?
>
> --
> 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


 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-08-2007
(E-Mail Removed) wrote:
> 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.

--
Lew
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-08-2007
(E-Mail Removed) wrote:
> ... 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".

--
Lew
 
Reply With Quote
 
jadrian@wi.rr.com
Guest
Posts: n/a
 
      10-09-2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ImportError: /usr/local/lib/python3.2/dist-packages/OpenSSL/SSL.cpython-32mu.so: Jason Friedman Python 0 12-27-2012 03:47 PM
Gem install extension in sub-directory under lib? Reid Morrison Ruby 1 01-19-2007 04:17 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
Netbeans, the classes in lib directory are not available vizlab Java 1 07-19-2004 05:00 PM
perl\site\lib\auto\... (DLLs, LIB, EXP etc) to another location under your dev directory? Kenjis Kaan Perl Misc 4 06-29-2003 08:28 PM



Advertisments