?
Solved

Applet spawning a separate Java application ?

Posted on 1997-04-24
3
Medium Priority
?
441 Views
Last Modified: 2013-12-29
Pedxing,
I need clarification, I put my further question in the "comments" section. After you answer this, I'll give you a really good grade. If you can't find the comment, please let me know...

I would like to have an applet spawn a separate Java process. I know how to create and use threads in Java, but I would like to have an applet spawn a completely separate application, interact with it via sockets, and then at some point kill the separate process.
I already know how to have separate processes communicate via sockets, I just don't know how to spawn a separate process and then kill it later.
Is such a thing possible in Java? It's okay if the applet and the process exist on the same machine. Sample code would be helpful (doesn't have to be elaborate)

Thanks in advance,
Dave

0
Comment
Question by:dgason
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
pedxing earned 200 total points
ID: 1219826
An applet cannot spawn an application on the same machine using standard security managers, as doing so would violate applet security and allow a rogue applet to have application-level control of your machine.  Not a good scenario!

I'm assuming here that your question refers to running a Java application, not another applet.  You can run multiple applets at the same time and if that is really what you want to do, let me know and I'll give you some code for that.

IF YOU ARE WILLING TO USE JDK 1.1.1

RMI (Remote Method Invocation) is the preferred method for doing this.  It requires the application to already be running (which is not precisely what you asked for).  It is also a very new API, which means that it won't be supported on a lot of browsers.  RMI programming is a big topic.  For information, take a look at:

http://www.javasoft.com:80/products/jdk/1.1/docs/guide/rmi/index.html

Pay particular attention to the tutorial, which gives you the code you were asking for.

IF YOU WANT THE APPLICATION ON THE SAME MACHINE (NO RMI):

Applet security can be relaxed in a couple of ways:

  a) replace the security manager in your browser. THIS IS DEFINITELY NOT RECOMMENDED!

  b) use a browser that allows you to configure the security options.  HotJava is the most flexible in this regard, I believe.  Again, this is a dangerous thing to do.

  c) More secure would be to use the Applet Signing system.  You can give permissions to signed applets to use system resources they wouldn't ordinarily be allowed to have.  Unfortunately, browsers which understand signed applets are in short supply right at the moment, so you lose portability.

However you get around the security restrictions, probably the easiest way to run the application would be to create a thread that had a call to java.lang.Runtime.exec().  It has the following forms:

  public class Runtime extends Object
  {
    ...
    public Process exec(String command) throws IOException;
    public Process exec(String command, String[] envp) throws IOException;
    public Process exec(String[] cmdarray) throws IOException;
    public Process exec(String[] cmdarray, String[] envp) throws IOException;
    ...
  }

IF THE APPLICATION CAN BE ON THE SERVER

Then you don't have a problem.  You can write an application that watches a particular port for messages, and a client that opens a socket to that port.  This works all the way back to JDK1.02.  Take a look at java.net.Socket.

Depending on the complexity and interactivity you wanted for the application, you could also store the application in the CGI-BIN directory and open a URL to it.  Look at java.net.URL, and possibly also java.net.URLConnection.

I hope this helps.
0
 

Expert Comment

by:pedxing
ID: 1219827
I'm sorry Dave, I'm afraid I can't do that.  (Sorry about that, I couldn't resist).

I don't see your comments.  You can try resubmitting them here, or email me: bruce@flair.law.ubc.ca.  I'll try to address any specific issues if I can.

And don't worry about the grade.  I'm answering your question in the hopes that someone will answer mine when I need it.  Points don't really interest me.  Thanks, though.

Bruce.
0
 

Author Comment

by:dgason
ID: 1219828
Hi!

I sent you an email with my additional questions. I hope that you can find a good answer!

Dave
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question