Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Importing from a Jar file WITHOUT unzipping it

Reply
Thread Tools

Importing from a Jar file WITHOUT unzipping it

 
 
Martyr2
Guest
Posts: n/a
 
      10-27-2008
Is there anyway I can put a bunch of classes into a jar file (no entry
point) and simply import that jar file into java applications I am
working on and access the individual classes through something like
dot notation? Much like a package, but actually zipped together in a
jar and my application be able to just pull out classes as needed.

Any guidance you can provide would be fantastic.


 
Reply With Quote
 
 
 
 
Andreas Leitgeb
Guest
Posts: n/a
 
      10-27-2008
Martyr2 <(E-Mail Removed)> wrote:
> Is there anyway I can put a bunch of classes into a jar file (no entry
> point) and simply import that jar file into java applications I am
> working on and access the individual classes through something like
> dot notation? Much like a package, but actually zipped together in a
> jar and my application be able to just pull out classes as needed.


Adding your jarfile to the classpath of the java applications seems to
match your expressed wishes to 100%.

Or did I misunderstand the question?
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      10-27-2008
Martyr2 wrote:
> Is there anyway I can put a bunch of classes into a jar file (no entry
> point) and simply import that jar file into java applications I am
> working on and access the individual classes through something like
> dot notation? Much like a package, but actually zipped together in a
> jar and my application be able to just pull out classes as needed.
>
> Any guidance you can provide would be fantastic.
>
>


What Andreas said. The normal method is to allow the user to install
and manage the extra libraries themselves. This makes thing easy for
pros who manage their systems themselves. Note that you have to include
the name of the jar file itself in the classpath.

CLASSPATH=/some/path/lib/myLibrary.jar

Just pointing to the directory won't work, that's for loose classes. I
think that .zip files will work exactly the same as .jar files, too.

Also, if your app is a .jar, you have to set the classpath in the
manifest file. The environment variable is ignored for "java -jar".

Other solutions:

1. Get a Java installer, those will install the needed library and set
the path appropriate.

2. Use JWS, it'll download the library as needed.

3. Use OneJar. This is an old and atypical solution, but if you just
need to package one jar inside of another for a quickie application,
it'll work.
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-28-2008
Martyr2 wrote:
> Is there anyway I can put a bunch of classes into a jar file (no entry
> point) and simply import that jar file into java applications I am
> working on and access the individual classes through something like
> dot notation? Much like a package, but actually zipped together in a
> jar and my application be able to just pull out classes as needed.
>
> Any guidance you can provide would be fantastic.


You can extract a file from a jar file to memory and load the
code from memory.

(I can create code to do so, if you are interested)

But as said by others: why bother - the normal classloader
should do it all for you.

Arne
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-28-2008
Mark Space wrote:
> CLASSPATH=/some/path/lib/myLibrary.jar
>
> Just pointing to the directory won't work, that's for loose classes.


It will if you wildcard the directory:

-classpath /some/path/lib/*

Normally one should eschew the CLASSPATH envar.

--
Lew
 
Reply With Quote
 
Andreas Leitgeb
Guest
Posts: n/a
 
      10-29-2008
Lew <(E-Mail Removed)> wrote:
> Mark Space wrote:
>> Just pointing to the directory won't work, that's for loose classes.

> It will if you wildcard the directory:
> -classpath /some/path/lib/*


Are you talking about some new feature of 1.6.0_10 here?

This year's spring I was attending some one-day Sun event, and the
speaker talked somewhat self-ironically about various features of
the "next big update 10": (Rephrased roughly from my bubble-memory)

"... We knew paths and wildcards for decades, but, the heck,
why did it take us till 1.6.0_10 to get them together???"
(Laughter from the audience, mostly programmer-types,
including me)

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-29-2008
Andreas Leitgeb wrote:
> Lew <(E-Mail Removed)> wrote:
>> Mark Space wrote:
>>> Just pointing to the directory won't work, that's for loose classes.

>> It will if you wildcard the directory:
>> -classpath /some/path/lib/*

>
> Are you talking about some new feature of 1.6.0_10 here?


<http://java.sun.com/javase/6/docs/technotes/tools/solaris/classpath.html>
> Class path entries can contain the basename wildcard character *, which is
> considered equivalent to specifying a list of all the files in the directory
> with the extension .jar or .JAR.


It came out before update 10.

If you're using obsolete or obsolescent versions of Java, YMMV.

--
Lew
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-29-2008
Lew wrote:
> Andreas Leitgeb wrote:
>> Lew <(E-Mail Removed)> wrote:
>>> Mark Space wrote:
>>>> Just pointing to the directory won't work, that's for loose classes.
>>> It will if you wildcard the directory:
>>> -classpath /some/path/lib/*

>>
>> Are you talking about some new feature of 1.6.0_10 here?

>
> <http://java.sun.com/javase/6/docs/technotes/tools/solaris/classpath.html>
>> Class path entries can contain the basename wildcard character *,
>> which is considered equivalent to specifying a list of all the files
>> in the directory with the extension .jar or .JAR.

>
> It came out before update 10.
>
> If you're using obsolete or obsolescent versions of Java, YMMV.


Based on the copyright date, this feature has been in place for two years now.

--
Lew
 
Reply With Quote
 
Andreas Leitgeb
Guest
Posts: n/a
 
      10-29-2008
Lew <(E-Mail Removed)> wrote:
>>> Are you talking about some new feature of 1.6.0_10 here?

>> <http://java.sun.com/javase/6/docs/technotes/tools/solaris/classpath.html>
>>> Class path entries can contain the basename wildcard character *,
>>> which is considered equivalent to specifying a list of all the files
>>> in the directory with the extension .jar or .JAR.

>> It came out before update 10.
>> If you're using obsolete or obsolescent versions of Java, YMMV.

> Based on the copyright date, this feature has been in place for two years now.


Hmm, you see me confused about whatever I must have missed on that
event. He did talk about something new in a (back then) future version.

Maybe the speaker himself mixed it up (didn't know it was there
already), or I misunderstood him. It's up to you to emphasize
the latter of these options

I didn't ever try to use the feature, so far, so it might have been
just under my hands the last couple of years ...

By that time, iirc, 1.6.0_04 (or up to 06) was current.

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-29-2008
Andreas Leitgeb wrote:
> Lew <(E-Mail Removed)> wrote:
>> Mark Space wrote:
>>> Just pointing to the directory won't work, that's for loose classes.

>> It will if you wildcard the directory:
>> -classpath /some/path/lib/*

>
> Are you talking about some new feature of 1.6.0_10 here?


Any 1.6 will do.

Arne
 
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
distinction between unzipping bytes and unzipping a file webcomm Python 10 01-10-2009 09:18 PM
Jython: Packing several .py on .jar, problem importing .py moduleswithin the .jar Gubatron Python 2 12-03-2008 06:01 PM
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM



Advertisments