3

I am beginner.it is first applet that i writing

i want run exe application with applet

java code

 package appletexample;

import java.io.*;
import java.awt.*;
import java.applet.Applet;

public class Welcome extends Applet {

    public void init() {
        String execommand = "C:\\windows\\notepad.exe" ;
        try {
            Process proc =  Runtime.getRuntime().exec(execommand) ;
        }
        catch(IOException ieo) {
            System.out.println("Problem starting " + execommand) ;
        }
    }
} 

java.policy.applet

grant {
  permission java.security.AllPermission;
};

i run this code in eclipse Run As->Java Applet worked and opened NotePade but when Export->Jar File(with .classPath,.project,java.policy.applet) and use in

Html

<applet archive="test.jar" code="appletexample/Welcome.class"  width=550 height=300>

in firefox say error access denied ("java.io.FilePermission" "execute")? how can fix this problem? firefox first enter image description here download my java and Html code

6
  • If this is a new project, consider dropping applets altogether. Use JNLP instead. Commented Apr 30, 2015 at 11:12
  • i am beginner,which applets drop?what is JNLP?please more explain Commented Apr 30, 2015 at 11:14
  • Just search around for JNLP; 10 minutes of searching and reading should get you started. Commented Apr 30, 2015 at 11:15
  • JNLP is for run exe application? Commented Apr 30, 2015 at 11:15
  • Read about JNLP here: docs.oracle.com/javase/tutorial/deployment/deploymentInDepth/… Commented Apr 30, 2015 at 11:17

2 Answers 2

2
+50

I assume that you just want to practice how to write a applet. For development purpose, you can create a keystore and then use it to sign your applet.jar.

Go: Start Menu > Execute > cmd.exe

Input:

cd /
keytool -genkey -dname "cn=CN, ou=OU, o=O, l=L, st=ST, c=C" -alias mykey -keypass mypass -keystore mystore -validity 3650 -storepass mypass
jarsigner -keystore c:\mystore -storepass mypass C:\path\to\applet.jar mykey

Then:

Refresh your HTML page.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for help but say error Your security have blocked a self-signed application from running
You can add the URL of this application to Exception Site List, which is located under the Security tab of the Java Control Panel. See java.com/en/download/help/appsecuritydialogs.xml#selfsigned
thanks,after create keystore say error security when add url to exception site,applet worked,
2

As beginner you should start with something much much simpler. When you play with Applets not all security rules apply. But when you come to real world (Browser in your case or, in other terms, sandbox) security rules are in force to prevent your code from harming the host computer.

What you are doing - you are running some program on the client computer when the client opens your web page with an Applet. That what viruses do. People will not want to allow it.

Of course you can the use Signed Applet approach or other ways to run program on another computer, but is it your goal? If it is to learn basics, then run easy stuff. Eventually, you will understand JNLP (Java Web Start) and other methods useful for you and your clients.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.