0

I wrote a simple java code that would take simple inputs from the user in the command window (of eclipse for me) using nextInt() and nextLine(). However, I realized that others need JRE (I believe?) on their computer to run the executable jar file made. So I was wondering if there is a way to get around that by making the app produce a window that is like the command window to have the same interaction as the command window in eclipse.

So, if I were to run the .jar or .exe then a simple window would pop up that acts like the console of eclipse displaying lines from System.out.println() and etc.

Eric
  • 71
  • 1
  • 9

2 Answers2

1
  1. To run a java program you need the jre. There is no way around that.
  2. If you need the console, nothing is stopping you from running the java program from the windows command line, which will do exactly what you ask for.
  3. You still need the JRE.

Unfortunately, when starting to learn Java with Eclipse, many people miss the opportunity to at least start to understand how to do the same from the command line, which is, if you ask me, good to know.

Florian Schaetz
  • 10,454
  • 5
  • 32
  • 58
0

For programs written in Java, they are compiled as a jar file, like you mentioned, and how these compiled versions of your source code differs from many other programming languages is that they do not contain the assembly/machine code like for example a compiled C program would have. They are instead compiled as bytecode. Which is special code for execution by a Java Virtual Machine. Here is a good Wikipedia reference: link

To answer your question, yes, others need a JRE (Java Runtime Environment) and this can be either:

  1. Installed by themselves (this is what you mentioned)

  2. Packaged together with your java app, to provide a download-and-click experience.

For option 1, assuming they already have it installed, they can simply run it by executing the jar file with javaw, more information on that is in this previously answered SO question

For option 2, the process is fairly lengthy and I'll point you to the official docs to refer to: self contained executables and Deploying java apps

If you have a more complex project with third party libraries and what not, look at this SO question

In the past, I've also found launch4j, a cross-platform wrapper to be very useful, it automates the process of going from jar to an executable (made a simple game that using Swing, simple and ugly thing it was), but the user still needs a JRE, nonetheless. :)

Hope this helps!

Community
  • 1
  • 1
matrixanomaly
  • 6,627
  • 2
  • 35
  • 58