-3

Need to create a jar file of 3/4 .java files and then create an executable file which just need to be double clicked to run the main program in mac PC.

Stultuske
  • 9,296
  • 1
  • 25
  • 37
  • 2
    Possible duplicate of [Convert .jar to an OSX executable?](https://stackoverflow.com/questions/2695214/convert-jar-to-an-osx-executable) – M. Prokhorov Aug 02 '19 at 11:11
  • a jar file is an executable. Just saying – Stultuske Aug 02 '19 at 11:11
  • What is jar file of 3/4, can you explain it ? – Sambit Aug 02 '19 at 11:12
  • @Sambit, 3 or 4 `.java` files. – M. Prokhorov Aug 02 '19 at 11:12
  • @Stultuske: Not quite - you can execute it, but it is not ["executable"](https://en.wikipedia.org/wiki/Executable) - it does not fit Mac's ABI, can't slap hashbang on it, `x` bit doesn't work on it, you must execute it by passing it into the `java` executable. Effectively, until it hits a JVM, it's data, not executable. – Amadan Aug 02 '19 at 11:15

1 Answers1

1

The first step is to compile your .java source files to .class files and potentially package them into a .jar file. One of your classes must have a main method so it can be run as a Java application.

I believe there are commercial products to create executable binaries but take a look at the GraalVM native-image tool. This tool can create an executable binary for Linux or Mac from a jar file.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114