0

I have made JAR file using Netbeans IDE's clean & build option. When I'm double clicking that Jar file, programs runs with javaw which is not showing me output in console i.e in command window

I want to make Jar file with Java.exe instead of jawaw using netbeans, which will run on double click or with windows task scheduler and display me output in command prompt. Please help me for this issue.

  • If I convert that Jar file to .exe file then I can't run with batch script and myprogram.exe will run with jawaw which will not show program execution in console. – Santosh Bhoir Feb 28 '20 at 20:13

2 Answers2

0

The jar file built has nothing to do with java or javaw when you double click it. Your machine is set to use javaw when running a jar.

To use java just run it from a command line:

java -jar myjar.jar

To run it via command line, you could always make a batch script to launch the jar.

Christopher Schneider
  • 3,745
  • 2
  • 24
  • 38
  • As you said, Machine is set to use javaw then how to set it to Java? @Christopher Schneider – Santosh Bhoir Feb 28 '20 at 20:04
  • If I converted that Jar file to .exe file then how will I give Java -jar myjar.jar – Santosh Bhoir Feb 28 '20 at 20:09
  • I never said anything about `.exe` or converting your jar. I mentioned `.bat`. You'd have a batch script that runs the command. – Christopher Schneider Feb 28 '20 at 20:13
  • Yes, whatever you said is working but when I convert it to .exe, It probably running with javaw. Is there is any way to change javaw to java? – Santosh Bhoir Feb 28 '20 at 20:16
  • Again, I have said nothing about `.exe`. I do not know where you are getting this from. I said you could use a batch file to run the command, and writing one to do this would be incredibly simple. https://www.windowscentral.com/how-create-and-run-batch-file-windows-10 – Christopher Schneider Feb 28 '20 at 20:22
0

On double click it will run with javaw by default. Better way to do so is make the Jar file and then convert it to .exe file with Launch4J with below settings,

  1. In Basic tab - Specify Output.exe filename.
  2. In Basic tab - Set the jar file location.
  3. In JRE tab specify the minimum JRE version.
  4. In Header tab - Change Header type to console instead of GUI.

And build the wrapper.

4th step will sort your problem, Which will run program in console(command prompt) on running .exe file either on double click or running from Windows Task scheduler.