Board index » jbuilder » Finding classes in external jar files

Finding classes in external jar files


2003-10-28 05:54:44 AM
jbuilder8
When I build a project jar file, usually that jar file does not contain the
JRE classes. When I execute the jar file, the jar file seems to find JRE
classes if they have been previously installed in the system.
However, when I try to find classes that happen to reside in other jar
files, which happened to be listed in the CLASSPATH, it seems that the
class loader should find those classes. However, I get
ClassNotFoundException instead.
I can include the library (jar) in my project and than everything is fine.
But I do not want to do that. I do not want to package the other jar file
with mine. I would like for a class loader to find the other classes in the
external jar files as listed in CLASSPATH statement.
Is this possible? Any ideas how could this be accomplished.
Thanks,
Z.
 
 

Re:Finding classes in external jar files

In <3f9d9425$ XXXX@XXXXX.COM >Zvonimir Ordanic wrote:
Quote
When I build a project jar file, usually that jar file does not
contain the JRE classes. When I execute the jar file, the jar file
seems to find JRE classes if they have been previously installed in
the system. However, when I try to find classes that happen to reside
in other jar files, which happened to be listed in the CLASSPATH, it
seems that the class loader should find those classes. However, I get
ClassNotFoundException instead.

I can include the library (jar) in my project and than everything is
fine. But I do not want to do that. I do not want to package the
other jar file with mine. I would like for a class loader to find the
other classes in the external jar files as listed in CLASSPATH
statement.
I'm guessing in a console window, you are doing this
% java -cp.;some.jar;other.jar org.myOrg.MyClass
where the list for -cp includes _all_ the required JARs, or
% set CLASSPATH=some.jar;other.jar
% java -cp.;%CLASSPATH% org.myOrg.MyClass
where you define the classpath in your script/console session.
Are you saying that neither of these approaches work,
and result in ClassNotFoundExceptions? If so, you
aren't including all the required JARs on your class
path. Be sure to print/echo the classpath to the terminal/
console before you call "java ...." and check to see
that all required JARs are there.
Or, are you suggesting that you don't want to add
any libraries to the "Required Libraries" tab of
your Project Properties, but hope that JBuilder
will use your system-wide classpath definition?
If it's the latter, you have to read the on-line
Help docs again. They clearly state that JBuilder
does not use any external classpath when running
or debugging your application. It assembles the
classpath precisely from those libraries described
in the "Required Libraries" tab.
Finally, one other piece of info:
One of the easiest ways to get a valid command-line
from an application which runs in JBuilder is to
go to the Message Pane of the running application,
and copy the first line. Put that into a .bat or
sh file and you have an almost 100% guarantee that
the script will successfully launch your program
in a console/terminal window outside JBuilder.
Paul Furbacher [TeamB]
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:Finding classes in external jar files

First of all thank you for responding to my question.
All I was doing is creating the Native Executable, where in the
Dependencies tab (within the properties) I have selected option to "Never
include any classes or resources". The reason I did not select anything is
that I have expected that the java Class Loader will find the correct
library from the environment's classpath.
After the compile I have simply clicked on the resulting exe. Since the
exe is actually a wrapper, I have expected that it will find the dependent
library classes from the environment's classpath. In other words, I have not
started my program with
java -cp .... org.MyOrg.MyClass
java -classpath .... org.myOrg.myClass
When I run the program from the JB IDE, the program runs fine, but this is
because I have defined in the project's path the dependent library, and the
IDE issues command
java -cp dependent.jar;..... org.MyOrg.MyClass
But, I think you have answered my question, although I do not like the
answer. I missed the point that JBuilder does not use any external
classpath when running an application.
I am looking now at possibility of using the .config files, but I have
problems there also. I have already posted another question on that topic.
Thanks again for your help.
Z.
"Paul Furbacher [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
In <3f9d9425$ XXXX@XXXXX.COM >Zvonimir Ordanic wrote:

>When I build a project jar file, usually that jar file does not
>contain the JRE classes. When I execute the jar file, the jar file
>seems to find JRE classes if they have been previously installed in
>the system. However, when I try to find classes that happen to reside
>in other jar files, which happened to be listed in the CLASSPATH, it
>seems that the class loader should find those classes. However, I get
>ClassNotFoundException instead.
>
>I can include the library (jar) in my project and than everything is
>fine. But I do not want to do that. I do not want to package the
>other jar file with mine. I would like for a class loader to find the
>other classes in the external jar files as listed in CLASSPATH
>statement.

I'm guessing in a console window, you are doing this

% java -cp.;some.jar;other.jar org.myOrg.MyClass

where the list for -cp includes _all_ the required JARs, or

% set CLASSPATH=some.jar;other.jar
% java -cp.;%CLASSPATH% org.myOrg.MyClass

where you define the classpath in your script/console session.

Are you saying that neither of these approaches work,
and result in ClassNotFoundExceptions? If so, you
aren't including all the required JARs on your class
path. Be sure to print/echo the classpath to the terminal/
console before you call "java ...." and check to see
that all required JARs are there.

Or, are you suggesting that you don't want to add
any libraries to the "Required Libraries" tab of
your Project Properties, but hope that JBuilder
will use your system-wide classpath definition?

If it's the latter, you have to read the on-line
Help docs again. They clearly state that JBuilder
does not use any external classpath when running
or debugging your application. It assembles the
classpath precisely from those libraries described
in the "Required Libraries" tab.


Finally, one other piece of info:

One of the easiest ways to get a valid command-line
from an application which runs in JBuilder is to
go to the Message Pane of the running application,
and copy the first line. Put that into a .bat or
sh file and you have an almost 100% guarantee that
the script will successfully launch your program
in a console/terminal window outside JBuilder.


Paul Furbacher [TeamB]

Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

{smallsort}