Results 1 to 8 of 8
  1. #1
    tonyleaf is offline Member
    Join Date
    Apr 2014
    Posts
    5
    Rep Power
    0

    Unhappy Applet classloader can't load Properties

    I'm developing an Applet that print a bar code using Jpos API. I need some jars and two configuration file. I've added jars to the classpath and configuration files in src directory. In Eclipse everything works fine.

    Java Code:
    DefaultProperties prop = new DefaultProperties();
    prop.loadJposProperties();
    SimpleXmlRegPopulator xmlReg = new SimpleXmlRegPopulator();
    xmlReg.load(wincor.jpos17.THxxx.xml");
    Everything works fine in Eclispe but I can't find property files when i call the applet from a web page. So I've checked the JavaPos sources and I've paste the loadJposProperties() and xmlReg.load("wincor.jpos17.THxxx.xml") content in my source code:

    Java Code:
      InputStream isD = prop.getClass().getClassLoader().getResourceAsStream(prop.JPOS_PROPERTIES_FILENAME); // (1) content of loadProperties
        if (isD != null){
            System.out.println("jpos/res/jpos.properties found");
        }else{
            System.out.println("jpos/res/jpos.properties not found");
        }
    DefaultProperties prop = new DefaultProperties();
    prop.loadJposProperties(); //(2)
    The same method is used to found wincor.jpos17.THxxx.xml. So when I call applet form the browser I get INPUT STREAM FROM PROPERTIES OK!! from (1) and jpos/res/jpos.properties not found from (2). So getClass().getClassLoader().getResourceAsStream works if i write it directly in my code, but doesn't work if i call a jar method.
    I am really at a loss for what to try next in the debugging chain. Thanks

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Applet classloader can't load Properties

    First off, don't use getClassLoader.
    Just use the getResourceAsStream() from the getClass() call.

    The two methods have slightly different path syntax and that could be mucking things up.

    Next is, getResourceAsStream is relative to the class itself and, since you're using a "relative" path it's possible your methods are, in fact, looking in different places.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    tonyleaf is offline Member
    Join Date
    Apr 2014
    Posts
    5
    Rep Power
    0

    Default Re: Applet classloader can't load Properties

    Quote Originally Posted by Tolls View Post
    First off, don't use getClassLoader.
    Just use the getResourceAsStream() from the getClass() call.

    The two methods have slightly different path syntax and that could be mucking things up.

    Next is, getResourceAsStream is relative to the class itself and, since you're using a "relative" path it's possible your methods are, in fact, looking in different places.
    Thanks for the reply.
    I can't recompile the jars but i know that the method does a

    Java Code:
    InputStream isD = getClass().getClassLoader().getResourceAsStream(prop.JPOS_PROPERTIES_FILENAME)
    and i can't use an absolute path :( method will search always for "jpos/res/jpos.properties". So i have to place this file in the same directory of the jars?
    it is so frustrating..
    if i can't use applet directly i need to develop a standalone application that communicates with the applet. Is it possible?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Applet classloader can't load Properties

    No.
    The file needs to be in the jar.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    tonyleaf is offline Member
    Join Date
    Apr 2014
    Posts
    5
    Rep Power
    0

    Default Re: Applet classloader can't load Properties

    Quote Originally Posted by Tolls View Post
    No.
    The file needs to be in the jar.
    Of course. The file is in my applet jar and in all 3rd part jars i reference in jnlp.. but still i get error..

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Applet classloader can't load Properties

    OK.
    So for situation (1), where is the file located in your jar (which is where I presume you want to load it from) and what class is DefaultProperties?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    tonyleaf is offline Member
    Join Date
    Apr 2014
    Posts
    5
    Rep Power
    0

    Default Re: Applet classloader can't load Properties

    is located in root folder of jar.
    Default properties is a class imported from JavaPos jar

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Applet classloader can't load Properties

    Since the filename does not start with a '/' then, I believe (again, using the class loader is likely to muck this up) that path is relative to the calling class, not to the root.

    As for DefaultProperties, I couldn't find that in the JPOS API.

    What does the documentation say about where this jpos file should be located?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. [SOLVED] Load applet from REMOTE directory
    By marksu988 in forum Java Applets
    Replies: 11
    Last Post: 08-02-2012, 02:46 PM
  2. Java Applet Will Not Load.
    By PaulMoretti in forum Advanced Java
    Replies: 3
    Last Post: 08-16-2011, 05:19 PM
  3. [ClassLoader] load byte array and use as jar
    By Dennis in forum Advanced Java
    Replies: 2
    Last Post: 02-15-2011, 04:51 AM
  4. [SOLVED] JAR applet won’t load.
    By Master Zero in forum Java Applets
    Replies: 14
    Last Post: 09-06-2008, 11:10 PM
  5. Not able to load a properties file
    By Happy9959 in forum New To Java
    Replies: 12
    Last Post: 07-29-2008, 07:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •