Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: JavaPos Applet

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question JavaPos Applet

    Hi everybody,
    i've developed a simple Applet that create a PosPrinter instance.
    To use javaPos i need a property file and an xml. I've added these to my src folder of my Ecplipse project and when i run the applet from Eclipse works fine.
    But when i try to run the applet frm a web page, through a jnlp file, i get an Exception in the init method "javapos/res/jpos.properties file not found".
    In the jnlp file i'm able to ref other external jar, but i don't know how to add external folder.
    How can i fix this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JavaPos Applet

    Can the files be moved into the jar file?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JavaPos Applet

    Yes, i get the two files inside the jar. I've also tried to clean java cache to remove previous applet version.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JavaPos Applet

    Is the code written to access the files while they are in the jar file? It can't use file I/O methods. It must treat the files as resources.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: JavaPos Applet

    Here's a very short article that contains the key line of code that you'll need to read a file that has been packaged up in your applet jar file: Accessing a resource within a .jar. Internet search term used: "read file in jar"

  6. #6
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JavaPos Applet

    Hello
    i've readed a lot of example. Now this is my code:

    public class adgPrinterAppletXml extends Applet implements ActionListener, EventCallbacks{
     
    	private static final long serialVersionUID = 1L;
    		SimpleEntry temp;
    	public void init(){
    		Properties p = new Properties();
     
                    try {
    			p.load(getClass().getClassLoader().getResourceAsStream("jpos/res/jpos.properties"));
    		} catch (IOException e2) {
    			e2.printStackTrace();
    		}
    		System.out.println("Getting Service Manager");
     
    		WNJposServiceInstanceFactory factory = new WNJposServiceInstanceFactory();
     
    		SimpleXmlRegPopulator xmlReg = new SimpleXmlRegPopulator();
    		;
            xmlReg.load("wincor.jpos17.THxxx.xml");
            System.out.println("3");
            @SuppressWarnings("unchecked")
            Enumeration<SimpleEntry> e = xmlReg.getEntries();
            while(e.hasMoreElements()){
    	            temp= e.nextElement();
            }
            System.out.println(temp.getLogicalName());
            try {
    			WNPOSPrinterTH230 printer = (WNPOSPrinterTH230)factory.createInstance("WN_TH230_U1_USB", temp);
     
    			printer.open("WN_TH230_U1_USB",this);
     
                printer.claim(0);
     
                printer.setDeviceEnabled(true);
     
                printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT, "7766554433222", 104, 60, 1 ,2 ,-13);
     
                printer.cutPaper(100);
    		} catch (JposException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
    	}
     
    }

    It worked fine in eclipse whe i run the class as an applet. The properties file is inside sources.
    When export as jar and run from a browser i get :
    access denied ("java.util.PropertyPermission" "*" "read,write")
             jpos/res/jpos.properties not found

    if i autosign the jar i get the same error and in addition:
    Missing Permissions manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Codebase manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Permissions manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Codebase manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Permissions manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Codebase manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Permissions manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Codebase manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Permissions manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Codebase manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar

  7. #7
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: JavaPos Applet

    Quote Originally Posted by tleaf View Post
    ...
    p.load(getClass().getClassLoader().getResourceAsStream("jpos/res/jpos.properties"));
    ...

    It worked fine in eclipse whe i run the class as an applet. The properties file is inside sources.
    When export as jar and run from a browser i get :
    access denied ("java.util.PropertyPermission" "*" "read,write")
             jpos/res/jpos.properties not found
    In order to check if jpos.properties has been packaged up into the right location within the jar file, please run
    jar -tf adg.jar
    (I'm assuming your JDK's bin directory is already in your system PATH environment variable. If not, run \absolute_path_to_jdk's_bin_directory\jar -tf adg.jar.)

    Quote Originally Posted by tleaf View Post
    if i autosign the jar i get the same error and in addition:
    How did you "autosign" the jar? Also, was it signed using a self-signed certificate, or with a trusted CA-signed certificate?

    Quote Originally Posted by tleaf View Post
    Missing Permissions manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Codebase manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    Missing Permissions manifest attribute for: file:/C:/Documents%20and%20Settings/Administrator/Desktop/applet/adg.jar
    This applies to signed applet jars only. The following web page may be of help:

Similar Threads

  1. Replies: 4
    Last Post: August 16th, 2013, 03:25 PM
  2. Replies: 3
    Last Post: July 3rd, 2013, 08:25 AM
  3. Replies: 1
    Last Post: May 7th, 2013, 07:49 AM
  4. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  5. Replies: 0
    Last Post: October 13th, 2011, 07:42 PM

Tags for this Thread