I have a given jar file. It should be run with an argument which starts up another java process (my program).
I use a process builder to start a process (givenJar). Within this process, my program is started.
MyMain1: run processBuilder -> "java","-jar","givenJar.jar","java -cp myPath MyMain2"}
My problem is : How do I attach debugging? Is it possible?
I hope, that it makes sense... ;-)
Oh ok....
I solved it:
Edit configurations
Choose MyMain2
In "Defaults" go to "Remote"
Copy command line
Go back to Application/Main2
Insert command line in "Program arguments"
Related
I am trying to make a console-based Java application that starts some batch scripts that do some other irrelevant things. Presently, I just want to find the proof of concept
I have tried to use the following code:
Runtime.getRuntime().exec("cmd /c start pathtomybatch.bat");
This works fine until I turn it into a .jar file and attempt to execute it. Then it opens the batch file in a new command prompt window, which I don't want it to do. I want to open the batch file in the same window that my Java program is running in. I read about the start command on TechNet and SS64 and found out that apparently adding changing start to start /b would open the program in the same command prompt window. However, when I try to run this:
Runtime.getRuntime().exec("cmd /c start /b pathtomybatch.bat");
NetBeans says BUILD SUCCESSFUL for both lines of code, but when I try the second line of code, no command prompt window opens and my batch file doesn't get started.
I want to know how I can make Java open that batch file within the same command prompt window without stopping the Java application or waiting for it to finish.
Also, as a tiny extra request, could someone tell me if I could do the same for an .exe file?
I'm on Windows 7, but I want this app to work for people using Vista or newer.
The extra window is coming from the start command you initiate. See https://www.windows-commandline.com/cmd-start-command/
A better pattern is to use
Process p = Runtime.getRuntime().exec("cmd /c pathtomybatch.bat");
Then make sure you loop until p.exitValue() no longer throws an exception (which means the process has exited), and while looping copy all available bytes from p.getOutputStream() and p.getErrorStream() to System.out and/or System.err.
I have this C# program i made and while i can run it fine by clicking the exe file or by clicking on a batch file, I cant start up the program on a java program I made to run it. I have tried this line of code and couldn't get the software to run.
Runtime.getRuntime().exec("nameOfTheExeFile");
or set it to the batch file i made that starts the program.
Runtime.getRuntime().exec("nameOfTheBatchFile");
Now the interesting thing is when I try it with the batch file i get an error saying that the file cannot be found but when i double click the batch file it will start the exe file just fine.
I have even tried to use Process but I am not getting any luck with that process as well
List cmdAndArgs = Arrays.asList(new String[]{"cmd.exe", "/c", "ProgramName.exe"});
ProcessBuilder pb = new ProcessBuilder(cmdAndArgs);
Process p = pb.start();
Strange thing is i dont get any error at all. Even when i try unit testing i don't any error's at all. Is there a process I am missing or something ? I am lost on what to do.
Update:
When i check on the task manager i can see that the program is running but not the exe version. I see ProgramName.vshost.exe , is there a reason for this to be showing and not the exe file ?
Since your program is command line program you need to start it from cmd. I'm not sure if this is the best way to do it, but it works.
Runtime.getRuntime().exec("cmd /c start nameOfTheBatchFile");
Batch file:
start cmd.exe /k "nameOfExeFile"
exit
I have 4-5 Instances of JAVA/JVM Running in Windows Server 2008 R2 Server, When I Open up Task Scheduler, I can see java.exe running, I am "not" able to find out the java instance details like what is the program? is it Tomcat? is it some Command Line etc?
From Task Manager , I could not get it? is there a way to find out from Command Line (or) Powershell?
In task manager, click View>Select Columns... and opt the command line column.
Open cmd and type following command, it will show all java processes:
jps -vlm
since you asked the powershell solution, you may use Get-Process java | select Processname, Path
Cheers,
GJ
It's %SystemRoot%\System32. The copy of java.exe is placed there during installation. You can also right click on the process and look up containing folder.
I just tried to execute a java command using runtime like this:
Runtime.getRuntime().exec("shutdown -s");
to shutdown the computer, but I am training on a project that will get both my electronics and computer skills so I want to execute an avrdude command to program the mcu from Java and make a GUI program. So I want the cmd window to be visible when I run the command. I just made it visible by:
Runtime.getRuntime().exec("cmd.exe /c start");
but I cant write on the window I just created, any help pls????
thanks all
Following would do it for you.
CMD.EXE /K your_command
I got an idea but still need some help!
What about making a .bat file and running it using java File class
but still when I make a bat file and try to run I get the command multiple times like this:
http://i.imgur.com/cMddMh5.png
but all I did was only write avrdude in the bat file:
http://i.imgur.com/PDbi2vJ.png
still need help in that!!
thanks for all answers...
EDIT::
I just looked it up in the internet and figured out a solution which is making a .cmd file instead of a .bat file and that worked great without looping thanks for all the repliers..!! :)
I have a Java application and i would like to spawn a new process(start a .bat file), that will essintially do the same thing as by double-clicking on it.
I have tried both Runtime.getRuntime().exec() and ProcessBuilder in order to spawn that process. Both those approaches work (they can start the .bat file), but my problem is that they do not actually do the exact same thing as by double clicking on it.
More specifically, this .bat file starts up a JVM (java.exe MyMainClass) which is configured to run using Windows SxS (side by side). Thus, i have created appropriate java.exe.config and java.exe.manifest files. When i doulbe click on that, the java application starts and the appropriate .dlls are loaded succesfuly (reason i need SxS).
My problem is that when i start the exact same .bat file (with the exact same arguments and process environment), either by using ProcessBuilder or Runtime.getRuntime().exec(), it doesn't seem to take into consideration my SxS configuration, thus the .dlls that i need are not loaded at all, resulting in errors.
Does anyone have any clue how to launch this .bat file the same way as windows laucnhes it when i am double clicking on it?
Additionally, does anyone have any experience with Java SxS deployment? I cannot really understand why ProcessBuilder ignores my SxS configuration.
Thanks in advance.
You can try starting a cmd window, which loads your application bat file:
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"C:\\path\\to\\the\\app.bat arg1 arg2\"");