Given the source code of a Java application with a GUI
when I compile it
and invoke it from the command line
then I would like it to run the GUI
and detach from the console it was invoked on, so I could resume typing there.
How can I modify the source code to achieve this?
An example of this behaviour - though not a Java program - would be ReKonq.
Note: I want to achieve this independent of the OS, i.e. I do not want to change the way I invoke it, but modify my public static von main(String[] args) method.
You can launch it from the command line with a & at the end of the line to run it in background :
java MyApplication &
If it is already launched, you can press ctrl + z and then type bg to get the same result.
(Assuming your are on Linux)
I don't think you can achieve this with pure Java, because in the end Java is just another process to the operating system you're on. As you want to avoid OS specific details, you may consider using a Java service wrapper. Some Apache software too use this, one that I'm aware of is this service wrapper.
Related
Our java program is suppose to call a program created by our vendor in C#. We are given two files
1.An exe file
2.An xml file...which its contents go something like this
<doc>
<assembly><name>someProgram</name></assembly>
<members>
<member name="P:SomeConnector.callSomeOtherProgram()">
<summary>a method to connect to some program</summary>
<remarks></remarks>
</member>
</members>
</doc>
We're clueless on how to so this. Anyone got ideas?
for running comman line in java use:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("MyOtherProg.exe progParameter1 progParameter2");
judging by your comment and question i think you have a class library, and the right way to approach this would be to just create your own C# program that calls the different method on that class library using the given xml as a program args or other way
Edit
your comment:
unning the exe manually (double click) shows up a wizard with an input
text field and some buttons which does different tasks. the idea is
for our java program to automatically run it and provide the fields
and execute which buttons we would like to trigger to do the function
we want. the java program just automates whatever is done manually
answer:
ok, now we're coking with fire :)
so, at this point i would go to the vendor and ask if i can get a class library instead of the current ui, as you want it running automatically, without Human intervention. while on it i would check if you got other .dll files with the program. if so investigate them using VS.
one last thing, if all is turn bad and you have to do clicks, it's not lost yet, but at this point you have a lot of work, and i can't help you from here, but i'll send you to a link to start what you need and you'll explore from there:
clicking robot
youtube video on the subject
I'm trying to build a simple text editor using Scala's swing library and I have to support two side by side windows. I was wondering if it was possible to have the second window be the terminal (bash, Unix). I haven't been able to find any information on the subject. Thank you for any information.
The question is: What is "the terminal"? bash is a shell but you need an implementation of a terminal which runs a certain shell. In general, I would say there are two possibilities:
Find a terminal implementation, which can be used directly in Swing. Maybe you this or that may help.
Implement your own terminal. You may want to start to wrap the shell with a ProcessBuilder. Now you can redirect standard input and output of this process so that you can control it programmatically (more information: here and there). Then you have to create the UI part which (1) reads input from the user and (2) displays the shell output in your window.
I'm very new to all Java related programming. For a school assignment, I've created my Java application using BlueJ. Apparently, the application should be able to run from the command prompt with the following line:
myapp -compress fileName
Honestly, I don't have the slightest idea about how to setup such:
My application has a Main class. Am I supposed to change it to be called myapp?
I've been running my app with java Main compress filename. I see that now I shouldn't be using the java key. But of course, as it is now, it won't work if I remove it. How can I run the app without it?
Is there a difference between having the compress argument I always use and the -compress one they tell me? Is that dash (-) any special?
Looking at this page: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html, it seems to insist that to run my program I do need to use the java key. And the dash seems to be used for something called options - there are standard and non-standard. However, there doesn't seem a way to make a "custom" one (-compress).
So my question is, how can I run my application with the above format?
The easiest way it to create a one-line shell script (if you're using Unix) or a one-line batch file (if you're using Windows). Call it myapp (or myapp.bat) and make it launch Java, passing the appropriate arguments.
As to the -compress argument, your main() takes an argv. You'll need to examine that to figure out what arguments have been passed to your program. You can either code everything yourself (very easy in your case), or use an existing framework:
How to parse command line arguments in Java?
I would just like to know whether it is possible to make a command prompt in Java.
My friend asked to make it, I wanted to know if it was possible or not. If it is possible, can someone suggest me some api or something? Thank you.
EDIT: I want to make it similar to windows command prompt
EDIT 2: I would like to make a SWING GUI application and put a command prompt inside of it.
Yes. Use the Process API.
You can run commands in Java using the Process API. You can also get the output and write input to the runned process. For more info, see this tutorial.
But if you want to make a terminal emulator (such as those in Linux) in Java,
I recommend having a look at JCTerm or JTA.
You must be careful how you start it.
If you start your program with java.exe then the console (input/output) is shown. With System.out.println("mymessage"); you can print (output) text to the console. With System.in you can read from the console. This delegates to the java.io.Console class (available throug System.console()).
If you start your program with javaw.exe, then you don't see the console. You must then create your own screen to allow input/output. This is the default on Windows.
Java can do console I/O and it can launch processes, so yes, it's possible. You'd use methods of System.in and System.out to display a prompt and read commands, and a ProcessBuilder to execute programs.
yes it's possible in java
your have to do some research on Java.lang & IO
Check the class java.lang.Runtime. It provides a couple of exec() methods.
Is it possible to start other application that are installed on the system with my java app and pass a file as a parameter to them? I have a client which receives videos from a server and I want my client program to start, lets say the VLC player with the file that I received. How do I manage to do that?
Use Desktop#open(). It will launch the platform default associated application to open the given file.
File file = new File("/absolute/path/to/file.vlc");
Desktop.getDesktop().open(file);
No need to hassle with Runtime#exec() or ProcessBuilder for which you would have to add platform detection and to write platform specific logics for.
Quite simply:
Runtime.getRuntime().exec("vlc [arguments]"); //Write all arguments as you would in your shell.
Make sure you catch all relevant exceptions
You can call the exec method on the Runtime object.
Runtime.getRuntime().exec("System specific command line text here");
You can run an external program pretty easily on Java 5+ with ProcessBuilder, including passing arguments and handling input/output streams.
eg.
ProcessBuilder movieProcess = new ProcessBuilder("/path/to/movieplayer", "/path/to.moviefile");
movieProcess.start();
Only used it myself executing non-UI stuff, I'll give it a quick go and see what happens with something like VLC.
Update - works a treat for flv on Ubuntu, UI is visible and accepts file arguments.