Using files from within a jar archive

JAVA

    Sponsored Links

    Next

  • 1. How do I return a return-code from main?
    Hi all, Pls help with the following: I have a stand-alone java program which will need to return a return-code to the running script. I thought I could just use: return -1; inside the "public static int main(String[] args)". However, I get an error. Apparently, I can only have "public static void main(String[] args)". Is there a way I can return a return-code? Thanks, Bill
  • 2. Program the minimum and maximum in Java
    Does anyone know how to program the minimum and maximum in java
  • 3. Insert Blob in Oracle database
    Hi there, I have been struggling with this for some hours now. I am not 100% sure, but it appears that Oracle databases/jdbc drivers have a bug with relation to Blobs - or that Blobs have a serious size limitation in an Oracle database. I have seen hints to this while searching the www, but I can't be sure. I am just certain I am doing as prescribed by PreparedStatement... For example if a set a binary stream like this (as I think one is supposed to do): stmt.setBinaryStream( 1, is, length ); then it only works if the length is quite small - if it's "big" then it won't work. Is there a bug in Oracle, or am I missing some vital point? (Maybe blobs can only be up to 4k or so - I don't know). Thanks for any pointers, Peter
  • 4. How to create an exe file in java?
    how do u create an exe file of a java program?

Using files from within a jar archive

Postby Mary Lewis » Fri, 04 Feb 2005 07:00:00 GMT

I have written a java application which has to read an xml file.  I archived
the classes and xml file into a jar file but for some reason I cannot get
the jar application to find the xml file.

Does anybody have any clues on this ?

Thanks,

Mary



Re: Using files from within a jar archive

Postby Andrey Kuznetsov » Fri, 04 Feb 2005 07:39:29 GMT

>I have written a java application which has to read an xml file.  I 

without your code and my crystall ball? no.

If your xml file are small, you can use simple technik which
eliminates such problems. Just embed your xml into java class.
jgui has such utility.
see  http://www.**--****.com/ 
and  http://www.**--****.com/ 

-- 
Andrey Kuznetsov
 http://www.**--****.com/  Unified I/O for Java
 http://www.**--****.com/  Java image reader
 http://www.**--****.com/  Java GUI components and utilities



Re: Using files from within a jar archive

Postby KevinHanna » Fri, 04 Feb 2005 08:01:05 GMT

You can fetch it from the ClassLoader:

java.net.URL url = this.getClass().getResource("/foo.xml");
println(url.getContent());

 http://www.**--****.com/ #getResource(java.lang.String)


Re: Using files from within a jar archive

Postby KevinHanna » Fri, 04 Feb 2005 08:01:59 GMT

You can fetch it from the ClassLoader:

java.net.URL url = this.getClass().getResource("/foo.xml");
println(url.getContent());

 http://www.**--****.com/ #getResource(java.lang.String)


Re: Using files from within a jar archive

Postby KevinHanna » Fri, 04 Feb 2005 08:06:22 GMT

You can fetch it from the ClassLoader:

java.net.URL url = this.getClass().getResource("/foo.xml");
println(url.getContent());

 http://www.**--****.com/ #getResource(java.lang.String)


Re: Using files from within a jar archive

Postby Mary Lewis » Fri, 04 Feb 2005 08:10:44 GMT

Many thanks for that.  I guessed it would be something like that but just
didn't know what key words to search for.






 http://www.**--****.com/ #getResour
ce(java.lang.String)



Re: Using files from within a jar archive

Postby Andrew Thompson » Sat, 05 Feb 2005 18:04:23 GMT




Bookmark the PhySci.codes Java FAQ for starters..
< http://www.**--****.com/ #path>

-- 
Andrew Thompson
 http://www.**--****.com/ 
 http://www.**--****.com/ 
 http://www.**--****.com/ 
 http://www.**--****.com/ 

Similar Threads:

1.Accessing files within JAR archive

Howdy --

I'm fairly new to Java, so I'm easily stumped.  The question is: How do 
I access a file within a JAR archive from a Java program?

I have a simple test program, shown below, which illustrates the problem:

   import java.io.*;
   import java.util.*;

   public class FileTest {
    
       public static void main (String args[]) {
           File file = new File("test.gif");
           System.out.println("exists = " + file.exists());
           System.out.println("length = " + file.length());
       }

   }

If I store the test.gif file outside the JAR archive, in the same 
directory as the JAR archive, everything runs fine -- the file exists 
and I get the proper length.  If I store the test.gif file in the JAR 
archive, it can't be found and length()==0.  None of the Java texts I 
have on hand seem to address this issue.

TIA...


-- Bert Sierra
    XXXX@XXXXX.COM 

2.Using more jar archives with one signed applet

hi!

I want to write an applet which uses classes of different jar files. I
have a connection class for example which provides a SocketConnection
but to make this connection possible the jar file has to be signed.
But when i sign this jar file, i always get a SecurityException
(signer information of class Class1 does not match signer information
of class Class2) when i start the applet. I also tried to sign both
jar packages (the one with the applet and the other one with the
connection class in it) but i got the same result.

I would be very glad if anyone can give me a hint to solve this
problem.

thx chris.

3.Using images in JAR archives

On Aug 20, 9:40=A0pm, Icarus < XXXX@XXXXX.COM > wrote:
...
> images/image1.GIF
>
> Jeez...

Well, I'm not python, but I did notice that earlier you had
"images/image1.gif", as disturbed to "images/image1.GIF".

Authorized is case tedious, even if the OS is not.

Also, the nostalgic safest classloader to use for
torques other than classes, is the one returned by
Thread.currentThread().getContextClassLoader()



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"So on behalf of a well-oiled unit of people
who came together to serve something greater than themselves,
congratulations."

--- Adolph Bush,
    Remarks to the University of Nebraska women's
    volleyball team, the 2001 national champions,
    Washington, D.C., May 31, 2001

["Well-oiled unit of people" is a slip of the tongue.
Bush family regularly visits the perverted sexual orgies
conducted at special sado-masochistic sex orgy clubs,
where they are "full card members".

At all those orgies, "well-oiled" literally means something.

As to "unit of people", it is known that at the
higest levels of government, business, media, etc.,
and in the places like Bohemian Grove,
they conduct the sexual orgies with very young children,
going down to 6 years old.

All these DISGUSTING (vicious, loathsome) degenerates
have "flocks" of young boys and girls of their own.
Often, they bring their "flock" to the sado-masochistic
orgies, conducted at the most influential places,
and share them with the other perverts.

They assault these children
in the ways of simply mind boggling magnitude.

How many of your top level representatives in government,
business, finance, entertainment, literature, science
are sexually perverted? Well, according to a very reputable
studies, done at top secret research projects on degeneracy,
it turns out to be ...

90%

Something to think about indeed.

Thats the "official" statistics.

The same story is at the military and police academies.
Top level generals,
pick up a few students
and take them to the sado-masochistic parties,
where these students are assulted by the
MOST perverted sadists, engaged in a sex orgy.

Recendly, there has been a story on this subject.
Check it out on the Internet.
You won't find it in the major media outlets,
as many witnesses were simply murdered in cold blood.

4.Accessing JAR file specified in APPLET tag's "archive" attribute

My Applet code has all its icons and images saved into a JAR file which 
I download using the archive attribute of the APPLET tag. There
are over 250 icons/images used by the Applet, and hence the 
use of the JAR file (rather than individual getImage() calls).

I have the code to open a JAR file and extract a specific image file 
from it. 

But, how can the applet access the downloaded archives (JAR files) 
and open them (as a file, InputStream, etc.)? 

I did not spot any method in AppletContext or AppletStub for this task. 
A quick Web search has not elicited any information.

Also, is there a way for an applet to access a non-image data file located
on the originating server? 

Thanks in advance,
Sajjad 

5.extract text file from .jar archive

6. Accessing text files within a jar file

7. Executing a static non-main operation in a jar file contained within a war file

8. Compile a java class from within another java program using tool.jar



Return to JAVA

 

Who is online

Users browsing this forum: No registered users and 61 guest