Results 1 to 4 of 4
  1. #1
    Psyclone is offline Member
    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    0

    Default Help deploying applet

    OK, I've been at this for almost 4 days now.

    I have the simple HelloWorld applet which runs fine in NetBeans IDE.

    Java Code:
    package gameinterface;
    
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    import javax.swing.JLabel;
    
    public class HelloWorld extends JApplet {
        public void init() {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello Arkoos");
                        add(lbl);
                    }
                });
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
        }
    }
    I'm trying to learn how to get it running on my website though and running into problems.

    I tried following Deploying an Applet (The Java™ Tutorials > Deployment > Applets), but it leaves out a lot of details and just gives 1 example.

    There are 6 steps to the process.

    1) Compile your applet's Java code and make sure all class files and resources such as images are in a separate directory.

    I compiled the code using Clean and Build in NetBeans IDE. It created class and jar files. The class file was named "HelloWorld.class"

    2) Create a JAR file containing your applet's class files and resources.

    I copied the HelloWorld.class file to my upload directory. In the upload directory, I then created my own JAR file named "hello.jar" by typing jar cf hello.jar HelloWorld.class at the command prompt. It successfully created a hello.jar file. Windows can see the hello.jar file as an executable jar file. I verified the contents of the JAR file by opening it with WinRar. It contains HelloWorld.class and the manifest file.

    3) Create a JNLP file that describes how your applet should be launched.

    Here is where I assume my problem is coming in. I made the JNLP file, but the directions from Sun are absolutely horrible. Actually, there is no tutorial for creating a JNLP file, just a vague example.

    Here is my hello.jnlp file...

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="" href="">
        <information>
            <title>Hello World Demo</title>
            <vendor>Psyclone</vendor>
            <icon href="GoldCastle1.png"/>
        </information>
        <resources>
            <!-- Application Resources -->
            <j2se version="1.6+"
                  href="http://java.sun.com/products/autodl/j2se"/>
            <jar href="http://[COLOR="Gray"]mywebsiteURL[/COLOR]/hello.jar"/>
    
        </resources>
        <application-desc
             name="hello Applet"
             main-class="HelloWorld"
             width="300"
             height="300">
         </application-desc>
         <update check="background"/>
    </jnlp>
    mywebsiteURL = the URL of my website and the same directory that contains the HTML file, JAR file, JNLP file, and CastleGold1.png file.

    4) Create the HTML page that will display the applet. Invoke Deployment Toolkit functions to deploy the applet.

    My HTML file looks like this...

    Java Code:
    <HTML>
    <HEAD>
    <TITLE> Psyclone's Web Page </TITLE>
    </HEAD>
    <BODY>
        <script src="http://www.java.com/js/deployJava.js"></script>
        <script> 
            var attributes = { code:'gameinterface.HelloWorld',  width:300, height:300} ; 
            var parameters = {jnlp_href: 'hello.jnlp'} ; 
            deployJava.runApplet(attributes, parameters, '1.6'); 
        </script>
    </BODY>
    </HTML>
    5) Place the applet's JAR file, JNLP file and HTML page in the appropriate folder(s).

    All these files are on the root directory of my web site which is where I'm trying to launch this from.

    6) Open the applet's HTML page in a browser to view the applet. Check the Java Console log for error and debugging messages.

    I get the following error...

    Java Code:
    exception: JNLP not an applet.
    JNLPException[category: Launch File Error : Exception: java.lang.Exception: JNLP not an applet : LaunchDesc: 
    <jnlp spec="1.0+" codebase="http://mywebsiteURL/">
      <information>
        <title>Dynamic Tree Demo</title>
        <vendor>Dynamic Team</vendor>
        <homepage href="null"/>
        <icon href="http://mywebsiteURL/GoldCastle1.png" kind="default"/>
      </information>
      <update check="background" policy="always"/>
      <resources>
        <java href="http://java.sun.com/products/autodl/j2se" version="1.6+"/>
        <jar href="http://mywebsiteURL/hello.jar" download="eager" main="false"/>
      </resources>
      <application-desc main-class="HelloWorld"/>
    </jnlp> ]
    	at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Exception: JNLPException[category: Launch File Error : Exception: java.lang.Exception: JNLP not an applet : LaunchDesc: 
    <jnlp spec="1.0+" codebase="http://mywebsiteURL/">
      <information>
        <title>Dynamic Tree Demo</title>
        <vendor>Dynamic Team</vendor>
        <homepage href="null"/>
        <icon href="http://mywebsiteURL/GoldCastle1.png" kind="default"/>
      </information>
      <update check="background" policy="always"/>
      <resources>
        <java href="http://java.sun.com/products/autodl/j2se" version="1.6+"/>
        <jar href="http://mywebsiteURL/hello.jar" download="eager" main="false"/>
      </resources>
      <application-desc main-class="HelloWorld"/>
    </jnlp> ]
    *I changed all the references to my website to mywebsiteURL.

    I assume my problem is coming in step 3 or possibly 4.

    I have read the following tutorials. Most of them so many times that it's driving me insane.



    Lesson: Applets (The Java™ Tutorials > Deployment)

    Lesson: Deployment In-Depth (The Java™ Tutorials > Deployment)

    Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)

    Lesson: Java Web Start (The Java™ Tutorials > Deployment)
    Can anyone please tell me what I'm doing wrong?

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    There is example here for java web start + applets
    so you can try to compare yours JNLP file with this one

    https://jdk6.dev.java.net/plugin2/jnlp/

    Watch out for java packages in src code
    when you use applets, maybe don't use at all for first example.

    Here is mine JNLP for my Swing application example
    that end user has to take from web server.
    Application specific values are bold.

    I had to put exported app sw1.jar and SwingExample.jnlp in this folder :
    /apache-tomcat-6.0.13/webapps/SwingExampleon
    on Tomcat server
    so end user must hit
    http://localhost:8080/SwingExample/SwingExample.jnlp
    to get swing application.


    Java Code:
    <jnlp spec="1.0+"
          [B]codebase="http://10.0.1.107:8080/SwingExample/"[/B]  
          href="SwingExample.jnlp">
       <information>
          <title>Simple Swing APP Demo</title>
          <vendor>MCE</vendor>
          <description>Temperature Convertor using Java Web start</description>
          <!-- <homepage href="http://java.sun.com/docs/books/tutorial/deployment/webstart/running.html"/> -->
          <description kind="short">Unesi i konvertuj</description>
          <offline-allowed/>
       </information>
       <resources>
    	[B]<jar href="sw1.jar"/>[/B]
    	<j2se version="1.2+" java-vm-args="-Xms128m -Xmx512m"/> 
    	<!--	<j2se version="1.6+"
    	      href="http://java.sun.com/products/autodl/j2se"/>	-->
       </resources>
      [B] <application-desc main-class="com.swing.examples.CelsiusConverterGUI"/>[/B]
    </jnlp>
    So i suspect you have problems with :
    Java Code:
    [U] <jar href="http://mywebsiteURL/hello.jar"/>[/U]
    TIP:
    "Any attempt to access the resources directly by using, say,
    a File or a FileReader object would cause a SecurityException
    to be thrown in the same way
    that it would if you tried to use them from an unsigned applet.

    If you want to use these classes and not be restricted to the JNLP service interfaces,
    you must sign the JAR file (see the previous section on signing JAR files)."


    So do you really need and applet?

    looking forward to discuss with you on this topics

    regards !

  3. #3
    Psyclone is offline Member
    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    0

    Default

    Thanks FON. I've been doing a lot of reading the last few days about sockets and networking. I think I'm going to just use applications and WebStart with .jnlp file.

    This was helpful.

  4. #4
    skmanyhats is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default

    You need to use the applet-desc tag instead of the application-desc when deploying an applet.
    More info on the structure of a JNLP file
    Structure of the JNLP File (The Java™ Tutorials > Deployment > Deployment In-Depth)

Similar Threads

  1. Deploying an applet with jsp
    By IamKira in forum Java Applets
    Replies: 7
    Last Post: 01-27-2010, 04:09 PM
  2. Problem deploying applet to browser
    By nfteodoro in forum Java Applets
    Replies: 4
    Last Post: 09-25-2009, 10:03 AM
  3. Deploying Servlets
    By gapper in forum New To Java
    Replies: 2
    Last Post: 01-17-2008, 12:43 PM

Posting Permissions

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