Shyam Prasad
Shyam Prasad

Reputation: 172

How to run a normal Java Program from a Java Applet?

I want to run a Simple java program from a Java applet. The following is the code for the program:

import java.io.*;
import java.util.*;
class Termi
{
    public static void main(String a[])
    {
        String[] nu={ "xterm","-e","gedit" };
        try
        {
            Process p=Runtime.getRuntime().exec(nu);
        }
        catch(Exception e){ }
    }
}

This is a program for opening the gedit text editor (I'm on Linux). Now, all I want to do is to execute the above program by clicking a button "Open" in an Applet. Can anybody tell me a way to do that?

Upvotes: 1

Views: 595

Answers (2)

Stephen C
Stephen C

Reputation: 718678

Generally speaking you won't be able to launch an external application from an applet. The Java sandbox in which an untrusted applet is executed is not permitted to launch external applications.

If you:

  • add the required permissions to your JAR's manifest,
  • signed your applet, and
  • convinced the end user / browser to trust the applet.

you could potentially work around this restriction. The following references discuss this:

However, this presupposes that you can convince the end users (or their system admin / security staff) to enable a Java plugin at all. A lot of people won't ... for obvious reasons.


IMO, you need to think of a way to edit files that doesn't involve using applets at all.

Upvotes: 4

Tymoteusz Abramek
Tymoteusz Abramek

Reputation: 41

It's impossible, you must rewrite java program to applet.

Upvotes: 0

Related Questions