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 / September 2007

Tip: Looking for answers? Try searching our database.

Accessing classes within a JAR file?

Thread view: 
utsavprabhu@gmail.com - 14 Sep 2007 10:22 GMT
Hi,

I have packaged my Java application using OneJAR, and I now need to
run some test scripts against this JAR file. However, I find my
classes virtually inaccessible within the jar. How do I get to them?

Regards,
superutsav
Andrew Thompson - 14 Sep 2007 10:32 GMT
...
>I have packaged my Java application using OneJAR, and I now need to
>run some test scripts against this JAR file. However, I find my
>classes virtually inaccessible within the jar. How do I get to them?

I suggest you either ..
a) Repack the single Jar using the SDK's own jartool, or..
b) Take it up with 'the makers of OneJAR' (read 'someone
who cares that it fails').

Alternately, you might take the much wider utility
solution of keeping the jar's separate but ensuring
that the ancillary Jar's are on the classpath when
the main Jar is invoked (there are a number of ways
to avhieve that, including a Jar manifest, or using
web start to launch the application).

Signature

Andrew Thompson
http://www.athompson.info/andrew/

utsavprabhu@gmail.com - 14 Sep 2007 11:14 GMT
> I suggest you either ..
> a) Repack the single Jar using the SDK's own jartool, or..
[quoted text clipped - 7 lines]
> to avhieve that, including a Jar manifest, or using
> web start to launch the application).

Hey thanks a lot for the suggested solutions! I think it's time for me
to figure out how to write a jar manifest.

Regards,
superutsav
Andrew Thompson - 14 Sep 2007 11:54 GMT
...
>...I think it's time for me
>to figure out how to write a jar manifest.

I am more experienced with the web start* way
of doing things, for a good overview of manifests,
you might try..
<http://java.sun.com/docs/books/tutorial/deployment/jar/>
..particularly the link to section titled "Working
with Manifest Files: The Basics".

* Web start does not need the manifest, but will probably
introduce other hurdles - e.g. most web start apps. need
to be digitally signed, unless they are very trivial.  You are
probably better off figuring how to use the manifest.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Roedy Green - 14 Sep 2007 12:11 GMT
>Hey thanks a lot for the suggested solutions! I think it's time for me
>to figure out how to write a jar manifest.

have a look at ant, jar.exe and genjar.  You can examine the those
jars with Winzip or other Zip archiver.

One-Jar has a custom ClassLoader and a custom Jar format.  I can't see
the compensating benefit.  Further the instructions on use seem even
more mysterious than ordinary jar building.

See http://mindprod.com/jgloss/ant.html
http://mindprod.com/jgloss/jarexe.html
http://mindprod.com/jgloss/genjar.html
http://mindprod.com/jgloss/onejar.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

brian.vanheesch@gmail.com - 14 Sep 2007 14:00 GMT
On Sep 14, 11:22 am, utsavpra...@gmail.com wrote:
> Hi,
>
[quoted text clipped - 4 lines]
> Regards,
> superutsav

Not sure about OneJar specifically, but I would question why you need
to deliver you application as a single jar file.  If you are including
3rd party tools (including open soource), then you will need to review
the individual tool's license requirements.  Some products require
that it is included in unmodified.

Barring that, I use 2 mechanisms to extract specific files from jar:

1) Access as a classpath resource:

   InputStream is = Object.class.getResourceAsStream ( fileName ) ;

2) Access as a jar file entry (you can get the jarfile from
System.getProperty( "java.class.path" ) & StringTokenizer it):

   JarFile jar = new JarFile ( jarFileName ) ;
   JarEntry entry = jar.getJarEntry ( fileName ) ;
   InputStream input = jar.getInputStream ( entry ) ;


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.