File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Distributing Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Distributing Code" Watch "Distributing Code" New topic
Author

Distributing Code

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
I've been coding for a while, but I haven't had to distribute anything until now. How do I distribute Java code that I can be sure will run on someone elses machine? I don't want them emailing me that it doesn't work only to find out they need Java installed or something. Will a simple JAR file work or do I need to turn it into an exe somehow? Does it need to install somewhere on their pc so that filepaths are setup correctly? I am basically confused on the entire process but want as simple a solution as possible.

Thanks in advance!


SCJA
~Currently preparing for SCJP6
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
If it is a java application, they will need a proper JRE installed. This requirement should be obvious. If you don't want a JVM to be required don't use Java, use C or C++.

It is possible to compile java code to a native executable, but from what I have read it isn't very good.

You don't need to bother with formal install procedures, that breaks platform compatibility in the sense the windows installer will be different then a RPM, which will be different then a DEB file.

Eclipse has it right, download, unzip where ever you want, and run it. The entry point is an ELF executable to get things started(which isn't necessary with simpler apps- an executable JAR will be OK) and of course it comes crashing down if it can't find a JRE.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Rusty Shackleford wrote:It is possible to compile java code to a native executable, but from what I have read it isn't very good.


So, if I don't want the user to have to install anything (this includes JRE and JVM) then my only option is an exe, right?

I was confused about the last sentence about an ELF file and a JAR..... more details please?

Thanks for the reply.
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
So, if I don't want the user to have to install anything (this includes JRE and JVM) then my only option is an exe, right?


Brian, I'm not sure that's really realistic. With Java software, there is some expectation that a JRE is present. Personally, I've never come across an instance of a Java program turned into an .exe-type file.

John.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Fair enough.

So, am I to understand that if I want to give someone some software to run then they must have a JRE and JVM installled? And if so, can I just deliever a JAR file which they can double click to run?

I want to give a completely untechnical person some code I wrote via email attachment. I would idealy like them to be able to just save it off to thier desktop, double click it, and have it run as expected. If it is more complicated then that then I need to write a simple batch installation file with the other things they'll need.

When I first started with java I installed JRE, JVM, JDK, etc, all at the same time so I am not sure which ones are needed to do what. It works in my environment..... and that's about all I know when it comes to distributing applications. Sad, I know... but you have to start somewhere, right?

All help appreciated.

And thanks as always!
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Brian:

They'll need the JRE at the very minimum, which has the JVM. If you want them to have something that's clickable, send along a batchfile that will run the following command:

java -jar <name_of_jar_file>.jar

John.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Great, thanks!

This still concerns me though. Traditionally applications are distributed with an .exe file which runs the program. The idea that Java doesn't/can't be turned into an .exe is bothersome. Sure, I can deliver a batch file along with everything, but most people and companies are expecting an .exe.

EDIT: Even if they have a JRE installed won't their system classpath need to be updated in order to use the java -jar comand from a batch file?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42038
    
  64
Brian Legg wrote:Even if they have a JRE installed won't their system classpath need to be updated in order to use the java -jar comand from a batch file?

No, the batch file can set any temporary classpath it needs to. No need to alter the system classpath permanently.


Ping & DNS - my free Android networking tools app
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
True. Ok, thanks all!
 
GeeCON Prague 2014
 
subject: Distributing Code