0

I have only been coding for a few days and I have one question that i just can't seem to find any information on. I was wondering what I would have to do to create an executable application out of my java code. I know that I can run my compiled code from the terminal by typing java helloworld for example when I'm in the right directory, but then I always have to navigate to the file manually and run it. I was hoping there would be a way to create a file that I could just click on and that would automatically run the program in the computer's terminal.

Any explanation would be much appreciated! I'm currently working on MacOS if it makes a difference. Thanks in advance.

edit: I'm using visual studio code to write my code

edit 2: I now understand that what I'm trying to accomplish is essentially to create a .jar file out of my .class file. Does anyone happen to know if there is a built in function in visual studio code to create a .Jar file? Some people are suggesting maven but I'm hesitant to download anything if im not sure it's necessary.

Ben133290
  • 9
  • 1
  • 2
    Does this answer your question? [How do I create an .exe for a Java program?](https://stackoverflow.com/questions/516399/how-do-i-create-an-exe-for-a-java-program) – akuzminykh May 29 '20 at 08:39
  • 1
    Does this answer your question? [How do I create executable Java program?](https://stackoverflow.com/questions/804466/how-do-i-create-executable-java-program) – denvercoder9 May 29 '20 at 08:39
  • MacOs can directly execute jars as long as an JRE is installed, so if you want to make java programs for MacOs there really is absolutely no extra work you have to do. Just double clicking the compiled jar should do the job – OH GOD SPIDERS May 29 '20 at 08:39

2 Answers2

0

It would be more helpful to know if you are using an IDE like Eclipse or IntelliJ, as these can automatically create executable jar files from your run configurations. They take care of automatically creating the files that tell your system where to find the main method to execute.

darthn
  • 151
  • 1
  • 9
-3

There are two steps:

  1. javac helloworld.java : This will compile your code.

  2. java helloworld : This will run the .class file created in step 1.

Ayman Arif
  • 1,456
  • 3
  • 16
  • 40