Execute java application with one icon - java

I'm trying to replicate the behavior of Linux where we create an application launcher using Alacarte providing it the command and file name and Icon using batch
However I have never used batch.
The batch file is in the same directory as the java application.
The Batch contains the command as:
java -javaagent:app1.jar -jar app2.jar
Which does the job but It keeps CMD running in the background which during work I always accidentally close it which turns out closing the java app.
How can I can make it so it will disappear after launching the app and keep the app running

On Windows use javaw, as this will not open the console window. See also java vs javaw

Related

Run Java Application at Windows Startup

How can I make java application start with Windows, without needing user interaction in netbeans ??
Follow the below steps:
Create a *.jar file using Netbeans
Create a batch file with the following contents:
javaw.exe -jar path/to/file/your_jar_file.jar
Create a basic task in the Windows Task Scheduler. Select "When I log on" as the trigger. Set the action to starting a program, and choose your batch file as the program.

How to execute java application (.exe / .jar / .bat) without displaying popup console at all?

I want to execute java application without displaying popup console. It because in 64bit applicaton, the GUI (console) will created in different session ID. I even use Java Service Wrapper, but the batch file still showing an popup console. So, how can I execute java application without displaying popup console? Or there any alternative way?
Running following command in command prompt, or through a batch file should help you:
start javaw -jar -Xms1024m -Xmx1024m <Your Jar File>
Refer to this thread for more.

Java - System.out.println() viewable from application?

I have a Java application that runs great :) While uploading files, it uses the standard output to show progress : "System.out.println(...);".
When I run it in Eclipse, well it works perfectly, but when I run the JAR file, I don't see any console/terminal showing up and printing what I print through "System.out.println(...),".
How can I open a new terminal when my application is launched (it is a Swing application)?
Basically I want to be able to run the Swing application and show information on the side in a terminal / console. Why? Don't worry about why I want to do this ;)
Thanks a lot!
Regards.
Open terminal and run application as java -cp yourjar.jar YouMain or java -jar yourjar.jar if you jar is runnable.
I believe that you do not see output because you are running your application using javaw - the special windows-only variation of JVM that does not have STDOUT at all. If you want to click your application and see output map *.jar file to be opened using java instead of javaw. Alternatively write bat file that runs your application. In this case you will see console.
Use java instead of javaw to launch your application. Double-clicking on a jar executes it with javaw. Instead, open a command line window and type
java -jar thePathOfTheJarFile.jar
If you want to have something double-clickable, then write a shell script containing this command, and double-click the shell script instead of the jar.

adding a java application to system configuration start up menu

I am creating a desktop application. I know how to add program to system tray, that consists of a continuous system process, I need instructions on how to add java code to system configuration startup menu. Like antivirus program which automatically executes on starting the system. would be of great help with example code
Write a batch file(.bat) which executes you java program. Add this batch file into the registry in such a way that it will be executed during system startup.
simply write following into your batch file
java filename
In linux you will hv to create a .sh script(executable) that will execute your java program.
put .sh in /etc/rc0.d using following commands
cp name.sh /etc/rc0.d/
chmod +x /etc/rc0.d/name.sh

closing a command line window in Java

I have created a small Java application in which there is some code that executes a batch file. The execution of the batch file leads to the command line window to be opened and to display some output messages. I would like to know if there is some way in Java to call this command line window to be closed from within the program...Thanks!
the command window should close automatically when the batch file completes.
and to run a batch file in background/invisibly, check other questions
Start java by using javaw or javaw.exe.
java (java.exe) runs with an associated console window,
javaw (javaw.exe) is the same but without the console window.
see the documentation for the java command.
On Windows also use start to invoke another shell
start javaw ClassName
I'm not sure for Linux&Co. Try using an & after the command to run it in the background
javaw ClassName &
The other way, closing the window from a batch started by Java:
I don't believe that is possible directly from within Java. You can only close the batch file by itself.
Is hard to help without knowing what that batch file is doing. You may try using the start command on windows or the & in Linux to run the process in the background (start has an option to open the window minimized [/MIN] or in the background [/B]).
Or try some hack like using AutoHotKey or some system functionality (some WinAPI-DLL or equivalent in other systems).
As an addition to NimChimpsky's answer:
If you run a batch file in Windows, Windows will automatically open a command window for the batch file, in case the batch file wants to print output or prompt for input. This also applies if you launch the bat file from a Java process.
Unfortunately, Windows itself apparently provides no way to launch a batch file without such a window. To avoid the window, you will have to run the batch file via some helper program. There are several available; google for "run bat no window" to find some.
If you just want the window to go away after the batch file terminates: That should happen automatically. If it does not, some program launched by the batch file is still running.
start /b [bat file name]

Categories

Resources