How to list files from .jar file in applet?

I have created applet and export all files to .jar file.
I use File.list() method in applet to list files from one directory and that works ok but if I try to do that from web browser it sends exception AccessDenied meaning that File.list() isn't allowed in browser.
I know what's the problem but I don't know how to solve it.
What I want is to read from directory list of files.
Help anyone?

I will post here my code so that can be seen what I want to do:
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JTextPane;
public class test extends JApplet {
     private static final long serialVersionUID = 1L;
     private JPanel jContentPane = null;
     private JTextPane jTextPane = null;
      * This is the xxx default constructor
     public test() {
          super();
      * This method initializes this
      * @return void
     public void init() {
          this.setSize(449, 317);
          this.setContentPane(getJContentPane());
      * This method initializes jContentPane
      * @return javax.swing.JPanel
     private JPanel getJContentPane() {
          if (jContentPane == null) {
               jContentPane = new JPanel();
               jContentPane.setLayout(new BorderLayout());
               jContentPane.add(getJTextPane(), BorderLayout.CENTER);
          return jContentPane;
      * This method initializes jTextPane     
      * @return javax.swing.JTextPane     
     private JTextPane getJTextPane() {
          if (jTextPane == null) {
               jTextPane = new JTextPane();
          return jTextPane;
     public void start(){
          File fileDir= new File("somedirectory");
          String strFiles[]= fileDir.list();
          String a="";
          for(int i =0;i<strFiles.length;i++){
               a=a+strFiles;
          this.jTextPane.setText(a);
Method init() is irelevant, it just adds JTextPane in applet.
Method start() is relevant, it runs normaly when started from Eclipse but from browser it sends exception AccessDenied.

Similar Messages

  • Please help: Example how to peploy application from jar file step by step

    Please help: Example how to peploy application from jar file step by step.
    All help appreciated
    Mike

    Thanks I will try these links
    Mike
    "Slava Imeshev" <[email protected]> wrote:
    Hi Mike,
    These links could be useful:
    http://e-docs.bea.com/wls/docs61////adminguide/appman.html
    http://e-docs.bea.com/wls/docs61////quickstart/quick_start.html
    http://e-docs.bea.com/wls/docs61//////ConsoleHelp/application.html
    http://e-docs.bea.com/wls/docs61///programming/environment.html
    Regards,
    Slava Imeshev
    "Mike" <[email protected]> wrote in message
    news:3ca0e94c$[email protected]..
    Please help: Example how to peploy application from jar file step bystep.
    All help appreciated
    Mike

  • How to get resources from jar-files

    Hi
    in my app I load an image via the Toolkit.getImage() method.
    Works fine if the app and the image are in folders on disk.
    It fails to load the image, if the app (and the image) is packed in a jar file.
    How can I get the image from there?
    I try to get the image as follows:
    String s = getClass().getResource("MyApp.class").getFile();
    AppPath = s.substring(0,s.lastIndexOf("/"));
    String PathToImages = "/images";
    MyImage = (Image)Toolkit.getDefaultToolkit().getImage(AppPath+PathToImages+"/logo32.gif");The App starts and works, it just fails to load the images.
    Any solutions??
    thanx in advance
    Herby

    This is actually pretty easy. First a little background.
    A Jar file is just a Zip file, with a few constructs for Java.
    The getResource() method is used to create a mapping to data within the Jar file, but is actually not necessary after you know how the mapping works.
    Just to give you an example of getResource:
    // returned is a url to the resource you want from your Jar file.
    URL myURL = MyClass.class.getResource("images/myimgage.gif");
    // then you can use this URL to load the resource
    Image img = getImage(myURL);If you were you look at the value of myURL you would see something similar to the followiing.
    jar:http://www.mywebsite.com/mydir/myjarfile.jar!/images/myimage.gifJust to break it down for you.
    The line always starts with the word jar:
    Followed by the path to your jar file.
    A sepearator !/
    Then the file you are loading from the Jar file.
    jar:     path_to_jar_file     !/     path_to_resource_in_jar_fileSo if you'd like, you could just create a URL object, and define the path to the object using the above method rather than using getResource.
    Anyway, back to your code. What I would do is print out what you get for:AppPath+PathToImages+"/logo32.gif"I'm thinking you might be getting 2 "/" in your path because I think:AppPath = s.substring(0,s.lastIndexOf("/"));will leave the "/" at the end and the next line you add the "/" in front of the image directory name. So you my have the following for your image path.mypath//images

  • How to load class from jar file dynamically?

    After I run my Java applicatoin, I need configuring the classpath of jvm to load some classess inside a jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know where the jar file is, what the jar file name is. All depends on the user to tell the jvm the details through some UI. I've tried to write: System.setProperty("java.class.path", "c:\myClass.jar");Class.forName("MyClass"); but failed.
    Can you tell my why and how?
    Thx

    After I run my Java applicatoin, I need configuring
    the classpath of jvm to load some classess inside a
    jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know
    where the jar file is, what the jar file name is. All
    depends on the user to tell the jvm the details
    through some UI. I've tried to write:
    System.setProperty("java.class.path",
    "c:\myClass.jar");Class.forName("MyClass"); but
    failed.That won't work. By the time it gets to your code it already has a copy of the original. You can't change it (short of modifying the JVM.)
    Can you tell my why and how?The usual way is to use a custom classloader.
    You can start by looking at java.net.URLClassLoader.

  • How to ban extracting from .jar file?

    Hello
    Problem of .jar file is: .class files can be extracted (with winrar ...) and decompiled. I don't want my classes to be decompiled. But I still need my jar executable of course.
    Is some solution which bans extraction without any impact on executability?
    Thank you very much.
    Tony

    Is some solution which bans extraction without any
    impact on executability?Hmmmm you could not put any class files in your jar. That would eliminate the extraction problem. Probably would be detrimental to execution.
    What do you think happens when your app runs? It just magically knows about your classes without extracting them?
    Not so much no.
    Use an obfuscator.
    Or if that's not good enough use another language or just panic.

  • Retrieving .txt file from jar for an applet

    I guess this is a newbie question but i checked the tutorial sessions and i am doing exactly what it says there but still...no luck:
    I'm trying to access a .txt. file stored in the .jar file where my applet .class file is stored. I'm using:
    String s = "myfile.txt";
    // get current Class loader
    ClassLoader cl = this.getClass().getClassLoader();
    FileInputStream is = new FileInputStream((cl.getResource(s)).toString());
    BufferedReader in = new BufferedReader(new InputStreamReader(is));But when the applet is viewer from the browser or from the appletviewer, i'm getting the FileNotFoundException:
    java.io.FileNotFoundException: jar:file:\C:\FeatureSelection\sFeatureSelection.jar!\myfile.txt (The filename, directory name, or volume label syntax is incorrect)
    I tried to use the following instead:
    FileInputStream is = new FileInputStream((myApplet.class.getResource(s)).toString());orFileInputStream is = new FileInputStream((getClass().getResource(s)).toString());but the same exception is still there.
    The jar file and the html file are all stored in this directory C:\FeatureSelection\
    The signed jar file is called sFeatureSelection.jar
    Any help would be greatly appreciated!
    Thanks.

    One way to get at files in a jar is to put the jar in the CLASSPATH and then just refer to the resource by its path in the jar. If the same path occurs in two different jars, then you only get the first one, based on the order of the jars in CLASSPATH, I think.
    The classloader is involved, which can be confusing, but an easy way to try this is:
    String s = "myfile.txt";
    URL u = this.class.getClassLoader().getResource(s);
    Object o = u.getContent();Now, you only really know that something matched that path and now it is in a URL.
    I think the Object will be a stream and you have to read() it or something.
    BTW: I encourage you to examine the URL, but it is not necessary to do so.
    If you have somehitng like a GIF image, then here is an example of how to work with that:
    http://www.devx.com/tips/Tip/5697
    Here is a way to get the bytes without involved the ClassLoader:
    http://www.javaworld.com/javaworld/javatips/jw-javatip49.html
    Take your pick.

  • Deleting file from .jar file

    I m having trouble with the Forum search, so sorry if this question has been answered before in this forum.
    If I create a .jar (or an .ear) file, then open the file using Winzip and then delete a file from the zip, does it corrupt the .jar file? I ran into such a problem recently where I could not deploy the application because the .ear file still contained references to the deleted file.

    No, Winzip doesn't corrupt jar files. But if you have something else that expects to find X in the jar file and you deleted X, it isn't surprising that problems arise.

  • Accessing files from jar file when running application?

    I have an application that when run should read an xml file (test.xml) from a jar file located in a resource folder. I do this:
        File f = null;
        URL url = this.getClass().getClassLoader().getResource("test.xml");
        try {
          f = new File(url.getPath());
    //      f = new File(url.toURI());
        } catch (Exception e) {
          throw new GeneratorException("Preload input not found!");
        }The file is found in the jar but when I want to use it I get problems:
    when doing:
    f = new File(url.getPath());
    this file is not found and when doing:
    f = new File(url.toURI());
    I get and:
    URI is not hierarchical exception
    Is there now way to convert the xml file in the jar file to a File object?

    fedevaps wrote:
    But is there now otherway to create a File from the URL?Only if the URL refers to a file in the first place. Which it doesn't when the URL refers to an entry in a ZIP file because an entry in a ZIP file is not a file.
    java.io.File refers to physical files in the sense that the operating system uses it. It can't refer to Files on remote machines, it can't refer to "files" stored in .ZIP files and it can't refer to some random String that you construct.
    Usually when you think you need a File object in Java, you don't actually need it. There are only a handful of operations that you can do with a File object that can't be done with a URL as well (deleting, renaming are two that come to my mind). Reading from it and writing to it works with a File as well as with an URL.

  • Can i load and run  .exe file from jar file??

    I generated a .jar file witch contain an executable (.exe file) under a directory called 'exec'. I can't execute this exe file using
    URL urlExecutable = DlgueLancement.class.getResource("/exec/myPrograme.exe");

    import java.io.*;
    import java.util.jar.*;
    import java.util.zip.*;
    public class Extracter
        public static File extract(File archive, String filename, File target) throws IOException, ZipException
            if( archive == null )
                throw new IllegalArgumentException("Null archive file");
            if( !archive.exists() )
                throw new IllegalArgumentException("Specified archive does not exists");
            if( !archive.isFile() )
                throw new IllegalArgumentException("Specified archive file is not a file");
            if( filename == null )
                throw new IllegalArgumentException("Null filename");
            if( filename.length() == 0 )
                throw new IllegalArgumentException("Empty filename");
            if( target == null )
                throw new IllegalArgumentException("Null target");
            if( target.exists() && file.length() > 0 )
                throw new IllegalArgumentException("Target file already exists and cannot be overwritten");
            JarFile jar_archive = new JarFile(archive);
            ZipEntry entry      = jar_archive.getEntry(filename);
            if( entry == null )
                return null;
            InputStream istream = null;
            FileOutputStream ostream = null;
            try
                istream = jar_archive.getInputStream(entry);
                if( istream.available() == 0 )
                    return null;
                byte[] buffer = new byte[istream.available()];
                istream.read(buffer);
                ostream = new FileOutputStream(target);
                ostream.write(buffer);
                return target;
            finally
                if( istream != null )
                    try{istream.close();}catch(Exception e){}
                if( ostream != null )
                    try{ostream.close();}catch(Exception e){}
    }

  • How to extract html file and folder from jar file

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

  • Applet : How to use Images in Jar file

    I want to put all images into a jar file to improve speed of loading.
    But how to invoke images from Jar file?
    Thanks.

    @Op. It's very important for a developer to know how to find information, and that skill usually comes with experience. Google is one of the best ways to find information and solutions to the most common problems.
    Kaj

  • How many Ways jar files from ear file on a jboss can be downloaded on clien

    Aoa
    How many Ways jar files from ear file on a jboss can be downloaded on client side
    like jnlp etc..
    Regards
    M Fazal Ur Rehman

    First, you need to be able to boot from the Recovery HD:
    Boot Using Command+R keys:
      1. Restart the computer.
      2. Immediately after the chime press and hold down the
          "COMMAND" and the "R" keys together.
      3. Release the keys when the Utilities Menu appears.
    Once at the Utilities Menu select Terminal from the Utilities menu in the screen's menubar. Now, you need to know where these new files are located. You move to any location using the 'cd' command such as cd /Users/user_name/Documents, then press RETURN. Replace user_name with your actual username. Next you need to do a directory listing to see if your files are in that location, Documents. Use ls -al to do a directory listing of the files and folders in Documents. If you find your new files there, then connect an external drive or flash drive. You will need to know the name you have assigned to this drive. It needs to be already formatted. Copy your files using cp /Documents/filename /Volumes/volname/filename. Replace volname and filename with those that apply. Press RETURN.
    Or take it to your local Apple Store and see if they can do the chore for you.

  • How do I display Canvas Graphic image (Not Iconic button) from jar file

    Hi all,
    I am currently using Forms 10g.
    I have gone through the tutorials on how to add Button Icons into Jar files for web enables forms .....so far so good
    This however does not explain what I actually want to do... since "graphic images are by nature embeded in the for rather than referenced ......so here goes ..
    I have a forms 10g application where all the individual form modules/canvases display a big banner (covering top 20% of the screen). This was done by importing the image straight unto the content canvases. As you know this now becomes a "graphic Image" now embeded(& not referenced by file name) on the canvas. Also bear in mind that this is actually different from an "Image Item" which is a block object.
    I dont know if this is possible, but what steps do i follow to make the image part of a jar file as opposed to my current situation. Please let me know if possible or not so I stop waisting development time looking for answers :)
    Another question is how do i make this jar file a library object so that we can vary the image as we wish
    NB: one other trick which i can think of is to create a giant push button across the screen to display the image and then stick it in a jar file !
    Cheers
    css_jay99

    I don't know about embedded images imported in from the builder, but there is a way to use READ_IMAGE_FILE into a BLOCK.IMAGE_ITEM where the images are all in a jar file stored on the OAS.
    Metalink Note:137397.1 explains it in details.
    Tony

  • How can i run a jar file as EXE on mouse click..

    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*

    amrit_j2ee wrote:
    *{color:#0000ff}how can i run a jar file as EXE on mouse click..is it possible in any way?????????{color}*Do you mean converting it from a jar file to an EXE file or do you mean that you would like to run the application by just double clicking it?
    If it's the latter then you need to make the jar file including a manifest.
    The manifest can be just a txt file with its content to be something like this:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.1
    Created-By: Somebody
    Main-Class: NameOfTheMainClass
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by buildTo make the jar file including the manifest, use something like this in your command prompt (of course you must have compiled your java file(s) first):
    jar cfm test.jar MANIFEST.txt NameOfTheMainClass.classAfter that you'd be able to run your application just by double clicking it.
    If you're a NetBeans user, you can build your standalone application by right-clicking your project and then going to properties => run => and choosing a Main class. After that right click on that project and "Clean and Build", locate the jar file in the "dist" folder and double click it =]
    Hope it helps,
    LD

  • How to protect the class files inside jar file.

    Hi Group,
    pls help me.
    my need is i created a executable jar file with certain classes.
    and i'm supposed to send it to my client.
    but if the client needs he can extract the class files from the jar and with the
    help of some decompilers he can convert class file to .java source code and read the whole
    stuff.
    how can i protect my jar file from these.
    is there any security mechanism for that
    pls help me.
    Regards,
    Ranjith.M

    In order to protect my jar file I tried the jar signer technology but it only protects the jar from modification so I need to know how to protect jar file from decoding of the contents inside.

Maybe you are looking for