Start a WS application from within a java program
Hi,
I need to start a WebStart application from within a java program. Therefore I develeoped a class which starts javaws.exe within its main-method like this:
try {
Runtime.getRuntime().exec(
"c:\\java web start\\javaws.exe http://a.b/c.jnlp"
} catch (Exception e) {
e.printStackTrace();
And that did not work. Java Web Start tries to start the .jnlp program but returns with the message, that the app-desc|applet-desc|installer-desc|component-desc is missing. But it is there: It is an applet and thus I defined an applet-dec.
I tried to do it from a command line with the followinf command:
java -Djnlpx.home="C:\abc" -cp "C:\abc\javaws.jar" com.sun.javaws.Main http://a.b/c.jnlp
And that works. But using this command from within my jjava prog using the Runtime.exec() method does not work.
By the way, simply type "javaws http://a.b/c.jnlp" at the command line does not work.
Can anybody help me? How may I start a .jnlp program within another java program.
Kind Regards,
Tobias Neubert
Hi,
I recently had a quite similar problem. At least the error message by the Java Web Start application on Mac OS X complained about the same error (app-desc|applet-desc|installer-desc|component-desc). It turned out to be some bad invisible characters in the jnlp file. I copied some sample from a web page which for some reason contained some unicode chars that the parser doesn't like. Use a different text editor or the less command on unix to see if there are some strange characters in you jnlp file.
But it seems strange that it does work from the command line and not from your code.
-Stefan
Similar Messages
-
Launching applications from within a Java program,
Hi all,
I wish to launch an application from a menubutton. I exactly wish to launch adobe acrobat reader and a specific file. Do I need to run a system command to do this, or more specifically, how is this done in Java?
Thanks,
JavaRobwhat if you have the entire exe as a byte array in
memory, write that to a file on the system, and then
run that file.
would that work?Yes but you would still have to use the Runtime class to excecute the file after you write it out, so it would just be easier to use the already made exe file. -
Executing a Java Program from within a Java Program
I need to execute the following Java Program from withing another Java Program. The office toolbar command line is
D:\WINDOWS\system32\java.exe -cp E:\Development\Eclipse\UpdateServer\Classes -server -showversion UpdateServer
I can find no combination of ProcessBuilder commands, including those that include "Cmd.exe /c" that will make this program run from within another Java Program. All the examples I can find only show how to run Windows *.exe programs. I keep getting error 123 from ProcessBuilder.start(), but I can find no documentation for error 123.Assuming your code didn't get mangled by the forum
(it's missing one "), it may be that your "-cp
E:\\Develop.." argument is getting quoted as it has a
space in it; try passing "-cp" and "E:\\Develop..."
as two arguments.That worked; specifically the following tested OK:
ProcessBuilder pb = new ProcessBuilder("D:\\WINDOWS\\System32\\Java.exe", "-cp", "E:\\Development\\Eclipse\\UpdateServer\\Classes\\", "-server", "-showversion", "UpdateServer" );
pb.directory(new File("E:\\Development\\Eclipse\\UpdateServer\\Classes\\"));
try{
Process p = pb.start();
InputStream is = p.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null)
System.out.println(line);
p.waitFor();
}catch(IOException ioe){
I was sure I tried that exact same code before, and it did not work, but now it does, at least at the top level (when it is in main of a test program). I will have to wait to try it until later when it is buried deep in a subroutine. -
How to call up an executable file (eg. MSPaint) from within my java program
How to call up an executable file (eg. MSPaint) from within my java program
Ummm... why would you want to get MSPaint anyway? Even in the absense of real software, Java's own graphics tools are way more sophisticated - with a little time and effort, you could write a simple paint package that beat MSPaint hands down.
-
How to start a browser from within a java program?
I want to make a help file for my java program and want to run the browser from the menu of my program.
How can I start my browser from my program?
A small code will be helpful.
Thanks.
NiteenThis should work on Windows without having to know where the browser is located. See http://www.javaworld.com/javaworld/javatips/jw-javatip66.html for more details
public static void viewHtml(URL url, boolean fixHtmlExtension){
String cmd = "rundll32 url.dll,FileProtocolHandler " + url.toExternalForm();
if (fixHtmlExtension){
//There is a bug in rundll32. For http requests, it doesn't like .html or .htm extensions,
//but replacing the 'm' with '%6D' works.
//This fix is not needed for file requests.
if (cmd.endsWith(".htm")){
cmd = cmd.substring(0,cmd.length()-1) + "%6D";
else if (cmd.endsWith(".html")){
cmd = cmd.substring(0,cmd.length()-2) + "%6Dl";
Process process = Runtime.getRuntime().exec(cmd);
try{
process.waitFor();
catch(InterruptedException e){ -
Displaying a shell from within a Java program
Hi,
For some long and twisted reason, I need to execute native programs from a Java program. Since this program is only every intended to be run on Linux, this doesn't bother me breaking the x-platform rules for Java! So, Runtime.exec() is the normal way to do this.
However, Runtime.exec() runs executes the command and then dishes basck the output once it's finished. The external program I wish to run takes a while and actually prints various pieces of feedback during its processing. I'd like to display this feedback to the user as it happens, rather than dumping it all at the end.
I can't think of anyway to do this. I've been looking for "Java shells" but they are reimplemented shells with only let you run classes on the classpath. Any ideas from the gurus around here?
Cheersimport java.util.*;
import java.io.*;
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + "> " + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class GoodLinuxExec
public static void main(String args[])
if (args.length < 1)
System.out.println("USAGE: java GoodLinuxExec <cmd>");
System.exit(1);
try
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + args[0]);
Process proc = rt.exec(args);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
stolen from this article and adapted to suit an os which does not start with the letter W. -
Running executable jar from within a java program
Is there a way to launch an executable jar in a java program? I tried wrapping the jar in an exe and calling it using Runtime exec() and though this approach works it does only for windows. I want it to work for unix/linux too.
jaki wrote:
Yes, but it's a sub process.Nope.
Hence the calling process doesn't quit unless the called one returns.Wrong.
My calling program is actually a jar and what Im trying to do is delete the jar after it's done running. But the above method (of launching a separate jar doing the deletion) doesn't seem to work for the above mentioned reason.Wrong.
If you could tell me any other way it would really be a big help.You don't need any other way. Maybe you need to allow some time for the calling program to wind up. 20 seconds may be overkill, but I'm not in the mood to find how short it can be and still succeed.
The two classes are packaged in separate jars.import java.io.IOException;
public class Deletee {
public static void main(String[] args) {
try {
String[] cmds = {"java", "-jar", "E:/temp/Deleter.jar"};
Runtime.getRuntime().exec(cmds);
System.exit(0);
} catch (IOException ex) {
ex.printStackTrace();
import java.io.File;
import javax.swing.JOptionPane;
public class Deleter {
public static void main(String[] args) {
File file = new File("E:/temp/Deletee.jar");
try {
Thread.sleep(20000);
} catch (InterruptedException ex) {
ex.printStackTrace();
if (file.delete()) {
JOptionPane.showMessageDialog(null, "Deleted");
} else {
JOptionPane.showMessageDialog(null, "Oops");
}Try it and see for yourself.
db -
How to use .dbf files zipped into a .zip file from within a java program
i have a .zip file containing several .dbf files.
the zip file is automatically downloaded regularly and data from the .dbf files is inserted into the database.
how do i facilitate automatic extraction of a zip file or how do i fetch data from the .dbf file? (this cannot be done manually)
anu.you could write a little polling class checking the zip file. you can use the java.util.jar package to extract the zip file (http://java.sun.com/docs/books/tutorial/jar/api/index.html). you could also use Jakarta ant (http://ant.apache.org/manual/index.html) to do this job (core task "zip") and call ant's target file on a regular basis (dependend on the OS you use, you can set os tasks/schedules).
-
Start an outside application from the database
Hello,
is there a way to start an outside application from within the database and pass some field values as arguments?
Thanks in advance,
Milosis there a way to start an outside application from
within the database and pass some field values as
arguments?What do you "within the database"? is it in sqlplus or ...?
SQL> !ls -ltr
-rw-r--r-- 1 oracle dba 2556 Dec 13 10:49 t.txt
-rw-r--r-- 1 oracle dba 2814 Dec 13 11:51 users.htm
drwxr-sr-x 2 oracle dba 512 Jan 16 14:00 test
-rw-r--r-- 1 oracle dba 5746 Jan 18 06:42 backup.log
-rw-r--r-- 1 oracle dba 2133 Jan 18 09:58 exlfile.txt -
How to execute a Perl program from within a Java prog
How do I execute a Perl program from within a Java program.
Lets say the Perl program that I want to execute is 'abc'. Now, 'abc' requires some input that I want to give it from within the Java program. How do I do it?
And finally, how do I execute that Perl program from within the Java program.
If I execute the Perl program alone then I do it in the following way -
perl abc inp1 inp2 inp3
where inp1, inp2, inp3 are inputs to the Perl program. I will not be able to change or modify the coding of the Perl program - 'abc' as I do not have access to its code. Its a kind of an application whose usual method of execution is in the above shown way. So, how do I execute 'abc' from within a Java program.what part of don't crosspost, don't you understand?
http://forum.java.sun.com/thread.jsp?forum=4&thread=427193 -
Executing a Perl program from within a Java prog
How do I execute a Perl program from within a Java program.
Lets say that the Perl program that I want to execute is 'abc'.'abc' requires some input that I want to give from within the java program. How do I do that? Then I want to execute the Perl program from within the Java prog. How do I do it?don't crosspost.
http://forum.java.sun.com/thread.jsp?forum=31&thread=427211&tstart=0&trange=100 -
How to run java programs from a master java program?
Hello,
I have several java programs which run from the command prompt. I am seeking help with code for starting java programs from within a java program. For example, a program called master.java works something like this:
import java.*;
create connection pool
create variables and result sets
start/run slave1.java (var1, var2);
start/run slave2.java (var3, var4, var5);
start/run slave3.java (var1, var4);
end of program master.java
Each of the slave.java programs will run for up to an hour. I do not want the master.java program to pause for each slave program to stop. Instead, the master program will keep running and multiple slave programs will be running simultaneously with the master program. When a slave program starts, it is on its own. Also, if possible, I would like to have each of these slave.java programs open in a new separate command window, so I can observe each slave program running in separate windows.
Any suggestions for code or helpful documentation are greatly appreciated.
Thank you,
LoganThank you all.
At the bottom of master.java I have successfully started a batch file with these lines:
String jcmd = "cmd.exe /c start c:/data/simulations/MsgViewCount2.bat";
Process proc = Runtime.getRuntime().exec(jcmd);
But I still cannot get a java program to start. Here is one variation I have tried:
String [] cmdArray = new String[2];
cmdArray[0] = "java";
cmdArray[1] = "slave1";
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(cmdArray);
This compiles, and no errors occur, but nothing happens.
Regarding this comment:
Why Runtime.exec? Either make the slaves Runnable or
just call their main() methods.
Oh, I see. Sepearate output. :PNone of the slave.java programs have any output.
Thanks again. -
Problem with creation of a jar file from inside a java program
Hi,
I am trying to create a jar file at runtime from within a java program.
I am able to create a jar file just fine using:
String[] jarArgs = new String[3];
jarArgs[0] = "cvf";
jarArgs[1] = "C:\temp\myjar.jar";
jarArgs[2] = "C:\temp\this";
sun.tools.jar.Main main1 = new sun.tools.jar.Main(System.out, System.err, "jar");
main1.run(jarArgs);However, when I look at the jar it puts the absolute path to the files inside such as:
C:\temp\this\is\my\package\Class.class
instead of only this\is\my\package\Class.class
When running the jar command from the command line it works just fine and I have the relative paths in my jar file.
Does anyone have any experience with this and could help me out?
Thanks in advance
Edited by: mruf on Apr 11, 2008 1:51 AMShouldn't jarArgs[2] = "-C C:\temp\this"
-
Executing C program from with a java program
How do you call a c program from within a java program, and parse arguments into that program and return something.
Cheers for any reply...Read http://www.javaworld.com/jw-12-2000/jw-1229-traps.html
-
Start a BO report from within a web-application.
Hi,
An enuser want to start a BO report from within a web-application.
The BO report ideally should not prompt for a login. The fact that we are using BO for reporting purposes should be transparent to the end users. The report should produce its output directly in Excel (pdf?) format. In WebI i can do a 'Save As' to obtain this, but it should go automatically so that the end users get their response directly in Excel
the report should be parametrized. These parameters will be added to the URL by the calling application.
To do a basic test of the Opendocument.jsp i created a number of test reports in WEBI, and i use the following URLs to execute them directly
http://s-olaf-vtst150:8080/OpenDocument/opendoc/openDocument.jsp?&sPath=[My reports]&sDocName=tmsd1&sType=rep&sRefresh=Y
http://s-olaf-vtst150:8080/OpenDocument/opendoc/openDocument.jsp?&sPath=[My reports]&sDocName=Yearselection&sType=rep&sRefresh=Y&lsSYear:=2002
So this covers points 1 & 4
What are the options for points 2 & 3?
Kind regards,
JohanThe BO XI 3.1 environment works quite well now.
Two more questions:
1. When a user being member of the Readers group, still sees the Edit button in Webapplication - Infoview. Is it possible to hide or disable that Edit button ?
2. Is it possible to make a user only seeing a part of the data in the universe ? When a query is run with a parameter, the user ses the parameter in the left column ... but in that way a normal user can change the value of that parameter giving him the possibility to see things he should not see. Making a separate query per user is overkill and too much work to do. Is BO XI 3.1 able to offer this possibility and how ?
Rgds,
Johan
Maybe you are looking for
-
I have an iPod Classic, the 2nd most recent version. I havn't had problems with it until a week ago. Before I had the new iTunes update, a week ago, it wouldn't show up in my Device's or "My Computer" , wont sync and It wouldn't charge either. I tho
-
Lets say I have a button that opens a popup menu with 2 levels: Fruits> Apple Banana Melon Vegetables> Carrot Potato Tomato Is it possible to get both values? I mean, to receive inform
-
Files getting corrupted on server
Hi, We have a problem where many files on a server appear to have become corrupted. I can see the timestamp has updated on the folder they are in at 9.12 this morning but there is no obvious update on the files other than they won't open. Below is an
-
I receive pdf files that open with checkered background and I can't read them.
Lately, whenever I open a pdf attachment from someone, it opens in Adobe with a checkered background. How do I get rid of this background?
-
BB App World Version 3.1.0.58 updated and is not working. Error Message seeking identity installation keeps failing to install. How do I solve this problem?