0

This is not my code. I'm just taking this for example because my real codes are long. I'm using Netbeans and i already enabled the Java Web Start on the project where this code located.

import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Tester2 {

    private static void createAndShowGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame("HelloJWS");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel label = new JLabel();
        label.setHorizontalAlignment(JLabel.CENTER);
        label.setFont(label.getFont().deriveFont(Font.PLAIN));
        frame.getContentPane().add(label);

        String text = null;
        try {
            Class sm = javax.jnlp.ServiceManager.class;
            text = "<html>You're running an application "
                    + "using Java<font size=-2><sup>TM</sup></font> "
                    + "Web Start!</html>";
        } catch (java.lang.NoClassDefFoundError e) {
            text = "<html>You're running an application, "
                    + "but <b>not</b> using "
                    + "Java<font size=-2><sup>TM</sup></font> "
                    + "Web Start!</html>";
        }
        label.setText(text);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

So when i run this code by pressing F6, it was always thrown to the catch. I don't know why. And when i try to build this code and open the Netbeans generated JNLP for this project, it shows Unable to launch the application. And when i click into Details it shows this two tab named Launch File, and Exception.

The Launch File has this log.

<jnlp codebase="file:///C:/Users/you/Documents/NetBeansProjects/Tester2/dist/" href="launch.jnlp" spec="1.0+">
    <information>
    <title>Tester2</title>
    <vendor>you</vendor>
    <homepage href=""/>
    <description>Tester2</description>
    <description kind="short">Tester2</description>
    </information>
    <update check="always"/>
    <security>
    <all-permissions/>
    </security>
    <resources>
    <j2se version="1.7+"/>
    <jar href="Tester2.jar" main="true"/>
    </resources>
    <application-desc main-class="Tester2,class"/>
</jnlp>

And the Exception tab has this log.

java.lang.NumberFormatException: For input string: "\Users\you\Documents\NetBeansProjects\Tester2\dist"
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at com.sun.deploy.security.DeployManifestChecker.verifyCodebaseEx(Unknown Source)
        at com.sun.deploy.security.DeployManifestChecker.verifyCodebase(Unknown Source)
        at com.sun.deploy.security.DeployManifestChecker.verify(Unknown Source)
        at com.sun.deploy.security.DeployManifestChecker.verify(Unknown Source)
        at com.sun.javaws.security.AppPolicy.grantUnrestrictedAccess(Unknown Source)
        at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResourcesHelper(Unknown Source)
        at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResources(Unknown Source)
        at com.sun.javaws.Launcher.prepareResources(Unknown Source)
        at com.sun.javaws.Launcher.prepareAllResources(Unknown Source)
        at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
        at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
        at com.sun.javaws.Launcher.launch(Unknown Source)
        at com.sun.javaws.Main.launchApp(Unknown Source)
        at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
        at com.sun.javaws.Main.access$000(Unknown Source)
        at com.sun.javaws.Main$1.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

How to get rid this problem?

Rich
  • 3,928
  • 4
  • 37
  • 66
  • Please show what you have tried. – frasertweedale May 07 '15 at 08:36
  • I have tried to directly put the directory, like PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("C:/Users/you/Downloads/awit.pdf")); – Rich May 07 '15 at 08:50
  • @JoshuaAlzate And what happens when you try that? Do you get an error? Note that you have an empty catch block, which is a pretty horrible idea since it hides any errors from you. – Kevin Workman May 07 '15 at 18:38
  • @KevinWorkman It does nothing if i run it in browser. But when i run it in IDE or in Applet viewer, it do what i want to do. PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("C:/Users/you/Desktop/awit_modified.pdf")); This is the code when i try it local. But i already tried this code too when i run it in browser. It still does nothing. – Rich May 08 '15 at 02:13
  • Fist, pull your head out of the sand. To do that, change `} catch (Exception ex) { }` to `} catch (Exception ex) { e.ptinStackTrace(); }`. Be sure the [Java Console](http://www.java.com/en/download/help/javaconsole.xml) is configured to show. If there is no output at the default level, raise the level and try it again. Print something to `System.out.println("..");` before that, to check the applet is using the updated code. – Andrew Thompson May 08 '15 at 05:10
  • @AndrewThompson System.out.println(".."); wont be showed in browser right? My program is all set when i run it in Compiler or Locally (jar). It just doesn't work in browser, but i properly embed the applet in html properly, it just doesn't work what they should be. – Rich May 08 '15 at 05:20
  • @AndrewThompson i got the idea that i should sign my jar to read and write locally. But i tried it, but still no luck. I don't know if i done it properly. Here's the link where i followed the steps http://www.developer.com/java/other/article.php/3303561/Creating-a-Trusted-Applet-with-Local-File-System-Access-Rights.htm – Rich May 08 '15 at 05:24
  • *"wont be showed in browser right?"* It will if the **Java Console** is configured to show, like I wrote immediately before that. Your inexperience suggests you have a ***steep*** learning curve before you will be able to successfully deploy this applet in actual browsers. But why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). – Andrew Thompson May 08 '15 at 05:24
  • @AndrewThompson neither do i don't want JApplet. Is there anyway how to put a Java application to web? And what printStackTrace() does? – Rich May 08 '15 at 05:32
  • *"Is there anyway how to put a Java application to web?"* The best way to deploy a Java desktop application is using [Java Web Start](http://stackoverflow.com/tags/java-web-start/info). They are installed & launched from a link on a web page. *"And what printStackTrace() does?"* Did you a) Try it? b) Read the [Java Docs](https://docs.oracle.com/javase/8/docs/api/index.html) for the method? The Java Docs are an invaluable resource, I have them open at all times in a tab of the browser. Don't expect to be spoon fed information that is in the docs. – Andrew Thompson May 08 '15 at 05:42
  • @AndrewThompson Would you like to see the link i gave? – Rich May 08 '15 at 06:03
  • @AndrewThompson I read this from another thread in StackOverFlow *You should realize that the Java Applet is considered an outdated technology. Most mobile devices won't run them and even some popular desktop browsers won't (Mac Chrome). What's more, Oracle now requires all applets to be signed in order to run with default security settings. This means purchasing a yearly (~$200) signing certificate. Java Web Start is not really fundamentally different from applets and will suffer the same issues as above.* – Rich May 08 '15 at 06:09
  • *"This means purchasing a yearly (~$200) signing certificate."* Wrong! There was a company in Eastern Europe providing free digital certificates recently. *"Java Web Start is not really fundamentally different from applets and will suffer the same issues as above."* And although a web start app. needs to be digitally signed, it suffers none of the (many) problems faced by embedded applets, especially with Chrome, and any browser that would put a further prompt before embedding an applet! Where did you read that? I need a link.. – Andrew Thompson May 08 '15 at 06:55
  • @AndrewThompson here is it. http://stackoverflow.com/questions/22305095/jframe-on-website , anyway so the best way to put it is JWS? And how can i digitally signed this? jarsigner? – Rich May 08 '15 at 07:29
  • Oh.. right. That was a specific situation where the OP was better off dropping ***all*** Java on the client side, but I added an extra comment to correct the statements about Applets/JWS. Note, BTW - who the top provider of answers for [Applet](http://stackoverflow.com/tags/applet/topusers) & [Java Web Start](http://stackoverflow.com/tags/java-web-start/topusers) is. (I have considerable experience in both!) – Andrew Thompson May 09 '15 at 02:47
  • @AndrewThompson i tried to convert my work to JWS, and i got an error when running it. I build it successful but when i run it, it shows ***java.lang.NumberFormatException: For input String*** *etc*. Any idea how to fix this? I already Google it and show of the result i see is in StackOverFlow with your comment there but it's not helping. – Rich May 11 '15 at 06:32
  • *"..it shows java.lang.NumberFormatException: For input String etc"* Wait ..what? Is that the console report of your code, or is it related to the JNLP file? Always copy/paste error and exception output - the entire stack trace (as an [edit to the question](http://stackoverflow.com/posts/30095642/edit)) & use code formatting! Also be sure to **check the JNLP using JaNeLA**, available at my [share drive](https://drive.google.com/drive/#folders/0B5B9wDXIGw9lUnJaUjA2cmlVRE0). – Andrew Thompson May 11 '15 at 06:42
  • @AndrewThompson *java.lang.NumberFormatException: For input string: "\Users\you\Documents\NetBeansProjects\DIY\dist" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at com.sun.deploy.security.DeployManifestChecker.verifyCodebaseEx(Unknown Source) at com.sun.deploy.security.DeployManifestChecker.verifyCodebase(Unknown Source) at com.sun.deploy.security.DeployManifestChecker.verify(Unknown Source) .....* Just like that. Is it related on JNLP. – Rich May 11 '15 at 09:41
  • You seemed to miss the part about **edit to the question**.. I cannot read stack traces in comments, add it to the question and use code formatting on it. – Andrew Thompson May 11 '15 at 10:07
  • @AndrewThompson i already edited the question. Would you mind checking it? – Rich May 11 '15 at 10:42
  • `` Have you checked that JNLP with JaNeLA yet? – Andrew Thompson May 11 '15 at 11:13
  • @AndrewThompson I already check the jnlp file through **JaNeLa** but i didn't understand what did it say here. "*Content type application/xml does not equal expected type of application/x-java-jnlp-file**, "*cvc-complex-type.2.4a: Invalid content was found starting with element 'security'. One of'{resources, application-desc, applet-desc, component-desc, installer-desc}' is expected.*", "*XML encoding not known, but declared as UTF-8*", "*Optimize this application for off-line use by adding the flag.*" and etc. – Rich May 12 '15 at 03:50
  • Please post output as an ***edit to the question*** (I won't tell you again!) where it is easier to read. Use code formatting (the `{}` button, not the other one you used for the current code formatted sections. None of those are 'runnable'. But.. `Invalid content was found starting with element 'security'. One of'{resources, application-desc, applet-desc, component-desc, installer-desc}' is expected.` .. that means that elements are out of the correct order. See [JNLP File Syntax](http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/syntax.html). – Andrew Thompson May 12 '15 at 03:56
  • @AndrewThompson my jnlp file is generated by NetBeans, is it incorrect? – Rich May 12 '15 at 03:58
  • @AndrewThompson you know, i think JaNeLa is useless. It can't help fix the problem i'm experiencing in JNLP. – Rich May 19 '15 at 10:06
  • Strange you say that. A lot of other people have found it to be a very useful tool. Ultimately though, it is a poor workman that blames the tools.. – Andrew Thompson May 19 '15 at 10:39
  • @AndrewThompson nope, i didn't blame the tool. I'm just saying my opinion about it. It can't identify the problem i said in my post which is the directory of my JNLP parse it in int. I don't know why. `` – Rich May 20 '15 at 08:27
  • @AndrewThompson Can you make an answer out of this? – Rich Jul 07 '17 at 06:27

0 Answers0