1

I'm still new to java and this is my first time trying to make something like a program that works without having jdk installed.
So I have my EditExcel.java and .class along with 6 .jar files which get imported in the EditExcel file via import.

Currently to run the program I need to use:

java -cp poi-4.0.1.jar;(some more jars);xmlbeans-3.0.2.jar;. EditExcel

to execute my .class file. I try to make this usable on a computer without jdk installed, so I can't use the java command. So I thought about making this into an .exe or .jar but I don't even know where to start and how to do it. I don't use an IDE but if its too complicated/inconvenient without I would try one.

So first off all would you recommend using a .jar or .exe and how do I get started? Thank you very much for helping me and sorry if this is something obvious.

Gorel
  • 11
  • 3
  • Most solutions that turn a Java program into an "exe" (the ones that work in all cases) are basically installers that install the JRE, and your app. – Erwin Bolwidt Dec 24 '18 at 01:33
  • Face it, Java is everywhere. :-D Anyway, regarding your Q. I would suggest you going with .jar. – MS90 Dec 24 '18 at 01:46
  • *"..a program that works without having jdk installed."* The only case I can think of, where a JDK (as oppose to a JRE) is required is if the app. is using the `JavaCompiler` or related classes. Note that Oracle now supposedly offers a packaging tool that will include whatever parts of the JRE are required for an app. to run. – Andrew Thompson Dec 24 '18 at 01:53
  • I tried it now with the command: "jar cfe EditExcel.jar EditExcel EditExcel.class" but as expected I get a java.lang.NoClassDefFoundError:... error when clicking on the .jar likely because I don't know how to tell the jar that it has to use the other .jar files in my folder in order to execute – Gorel Dec 25 '18 at 00:20

1 Answers1

0

I am using Java Eclipse IDE Photon (4.8) and to make a .jar file you need to go to file > export. Note: Not all editors do this the same way.

You will see this:

https://i.stack.imgur.com/u68hh.png

Once you are there go to Java and expand it and double click the Runnable JAR file option:

https://i.stack.imgur.com/xUjQ3.png

After that find the package you want to convert into a JAR file with the main method in it, save the JAR where where you want it and make sure the 3rd option is enabled in the screenshot. Then hit finish:

https://i.stack.imgur.com/PpDEt.png

Finally, locate (with the cd command) the JAR File via Command Prompt to where you saved it. Run it with this command: java -jar jarfilename.jar.

Hope it helps!

EDIT: My solution ONLY works if the JRE is installed on the side that is running it. Meaning that their PC may not recognize in cmd the java command.

Here is a link that might help: http://burnignorance.com/java-web-development-tips/run-jar-without-jre-on-windows-machine/

Compiler v2
  • 3,509
  • 10
  • 31
  • 55
  • So I installed Eclipse Java but understanding whats going on in an IDE seems like a project itself. In the Runnable JAR File Export I only can set the Export destination to .zip files or .jar files. The only thing I have is a normal folder with my EditExcel.class, EditExcel.java and some .jar files that I need for the imports. So I took everything I needed and packed it into a .zip, but even then the Lauch configuration is just a drop down menu with blank spaces. – Gorel Dec 26 '18 at 02:24
  • The JAR files that you need for the imports, are they the *import* statements at the top of the .java file? Where your code is? Or are they external JAR files that act as an external library for your project? Don't worry about the .class file, you cannot run it, nor it is for humans to use. – Compiler v2 Dec 26 '18 at 19:41