I have a java code, and I want with an actionlistener when a menuitem is clicked to automatically open a file and click "run" (which executes and compiles a code in the external program). It is the key F9 to do this action. Is there a way to perform this action through java?
Asked
Active
Viewed 680 times
0
-
Although an interesting question, how you are trying to solve your problem sounds way too complicated. You don't need to start Eclipse or send a key press to Eclipse to compile and start a Program (at least that is what i understood that you are trying to do). Maybe you can better explain your problem. Are you programming an Eclipse Plugin? Is what you actually want a Run Configuration? – kutschkem Oct 02 '13 at 15:27
-
I have a java code which does some actions in an external file of a program. I need to find a way to access this file through my java code and hit the F9 key inside that file, which makes the program run. @kutschkem – user2598911 Oct 02 '13 at 15:38
-
I am against marking this as a duplicate of a question dealing with how to start a Process in Java. This question goes way beyond that (alothough i still doubt that what OP asks is what he would really want). This question is about simulating UI actions. I agree that just starting a Compiler as external process and then starting the compiled Program is probably the better solution. But the question is more about simluation of UI actions, i feel. – kutschkem Oct 03 '13 at 12:39
1 Answers
0
What you are looking for is probably
Runtime.getRuntime().exec("myCommand");
where "myCommand" is a valid command on your system. The problem might be that if you want to run your program on different platforms, you will probably have to customize the command depending on the platform your java program is running on, i.e. you are loosing platform independence.
As Jashaszun pointed out, there is already a thread dealing with this issue: Starting a process in Java?
-
-
It is a different program (different file) and I need to open it and simulate the key press F9 (or just make it run), through my java code. @rich – user2598911 Oct 02 '13 at 15:26