Archived

This topic is now archived and is closed to further replies.

Telamon

[java] Distributing Java Programs

Recommended Posts

Hi, I took a class on Java last year and am using it at my job at IBM, but I have a really basic question that I''m ashamed not to know the answer for. If I had a Java app I wanted to distribute to people, without giving them the source, how would I package it? In MSVC or .NET I would just compile the sucker to an .exe, zip it up, and upload it to my website. I''ve poked around on the net for a while and decided I''m not looking for a way to compile Java to a native .exe (since then I''d lose cross platformness). So I want to package my code into some kind of self-executing, IDE-free, neat little app with a program icon. Is this what .JAR files are? Limewire is written in Java, but works like this. It''s frustrating that the answer to this problem isn''t self-evident. It might be because I''m using IBM''s WebSphere Studio, whose UI is so backward, unintuitive, and primative compared to the .Net GUI, which is what I''m used to. Thanks! ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Coding: http://www.stanford.edu/~jjshed/coding Miscellany: http://www.stanford.edu/~jjshed

Share this post


Link to post
Share on other sites
If I understood correctly, you should use a JAR file (which combines many things such as class files and resources like images) into one file, and there's a way to configure the JAR file to launch a certian file in it. I don't belive a JAR file can have it's own icon though.
How to create a JAR file: http://www.javacoffeebreak.com/faq/faq0028.html
How to configure the manifest file to launch a certian class file: http://java.sun.com/docs/books/tutorial/jar/basics/mod.html

Also, just a quick note on the not distributing the source with it, just in case you didn't know, there are java decompilers which would be able to get the source, so you should use an obfuscator (sp?), that way if they decompile it, (and i speak from experience) it's very hard to understand what the program does.

Hope this helps, good luck on your project!

[edited by - Kajsngweaaweg on July 8, 2003 2:31:39 PM]

Share this post


Link to post
Share on other sites
A word to the wise on jar files. Depending on that kind of resources that are going to be included in the project, there might be changes you will need to make to your code to get the stuff out of the jar file. Not anything hard, but just know there could be differences. I put a little application in a jar file for class, along with the image files I was using, but I had to completle change the code when I made it an applet, because of the security issues of trying to get stuff from the jar file while in the applet. I did not work like the regular code where the *.jpg files were just in the same folder. And know that a jar file is just java''s zip file. You can open a jar file with winzip and see everything inside. It is not like an executable.

I think, therfore I am.
I think?

Share this post


Link to post
Share on other sites
Ick. None of that sounds too great. How to serious businesses sell their Java-based products if anyone can just open up their JARs and rifle through all their resources? What is the professional solution to this problem?

Share this post


Link to post
Share on other sites
This may seem like a strange question, and I don''t mean to insult you. But, if you work at IBM, wouldn''t you have access to whatever they used to distribute Java applications? I know IBM has some Java-based products already (i.e. Websphere).

However, if you''re looking for something to distribute non-commercially or just for free, you could try exeJ or exe4j. I tried exe4j, but couldn''t get it to work correctly, however, I''m sure others have.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Many applications, written in C/C++, are distributed with an installer exe. Why not do it in Java? It´s possible. For example, you could download a free version of the very good program InstallAnywhere:

http://www.zerog.com/

Regards
Johan

Share this post


Link to post
Share on other sites
My understanding is that the .class file IS pre-compiled. Unless somebody has a byte-code decompiler, they can''t read your source if you distrubute the class file. The same danger exists in C++/.net with Machine-Language to ASM decompilers, though I bet byte-codes are less cryptic.

As far as a self-executing java program, I know that windows doesn''t support java natively (unlike linux, ect) so you''d need to package your .class with a JVM, or a byte-code interpreter. If somebody wants to excecute your application under linux then they can just run it with javac. Could you distribute your code with a .bat file perhaps?

If your target platform is Windows, I can''t think of a simple way to go about it.

Share this post


Link to post
Share on other sites
Using a jar file is how professional software is distributed. Some use multiple jars. Some also make platform specific installers, but with the same jar files in the installers.

Some companies also convert to platform specific executables for increased execution speed.

If you want to use a jar, you can make it so the user only has to double-click(Windows) on it buy including the following line in the manifest file:

Main-class: YourMainClassFile.class





First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
_Infinity, about the byte code decompiling, if you were refering to my post, I was just warning Telamon that if he was concerned about making sure nobody got the source, he should use a obfuscator because there are many Java byte code decompilers, and contrary to what many obfuscator programs boast, their program does not make it impossible to decompile the .class file, it simply makes it so when people do, it''s very hard to understand what it does (all variables are renamed to single letter names, same with methods, etc).

Share this post


Link to post
Share on other sites
quote:
Original post by Telamon
Ick. None of that sounds too great. How to serious businesses sell their Java-based products if anyone can just open up their JARs and rifle through all their resources? What is the professional solution to this problem?


easy. its called not using java. i have yet to see a serious and/or professional software product use java.

Share this post


Link to post
Share on other sites
quote:
Original post by Rocket05
quote:
Original post by Telamon
Ick. None of that sounds too great. How to serious businesses sell their Java-based products if anyone can just open up their JARs and rifle through all their resources? What is the professional solution to this problem?


easy. its called not using java. i have yet to see a serious and/or professional software product use java.


Java is used in many professional pieces software. You don''t see it much though because it is not used to make commercial software and games. But Java is in high use for enterprise level software, such as web site back ends and multi tier data access apps.



First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
With a standard c/c++ program, sesitive reasources are often stored in a proprietary (well, not always) file that they will only know how to use. Java can do the same thing. For the class files, you have to send them through an obfuscator, or they can be decompiled almost back to the original. packaging into a JAR can give you that whole one exe feels too.

Share this post


Link to post
Share on other sites
Also, a comment one people being able to open up your JAR file and view the resources, there are resource extractors for exe files which could get all the images you use (unless you encrypt them.. and still, unless it was strong encryption people could easily break it). 2 mins of searching google would come up with an exe resource extractor, so JAR files aren''t that much more insecure than exe files (at least in the resource extracting aspect).

Share this post


Link to post
Share on other sites
The simplest form of obfuscation for Java is to turn debug compiling off when you distribute.



First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
There is one game that's written in Java. http://www.puppygames.net/

It may not be selling in stores, but it's getting great reviews, and is sold off the site. It's an awesome game. At least download the demo. They used a program called JET that will generate native files for Windows, Linux, and OSX. It also generates an installer. This also eliminates any need for a JVM if you don't use AWT or SWING.

The down side is that it costs some $5k, if I remember correctly.

[edited by - nickwinters on July 10, 2003 7:34:55 PM]

Share this post


Link to post
Share on other sites
Anyone who is serious about code security won't trust hardware (that includes everyone from government agencies to cable-TV providers). All popular commercial programs get cracked (commonly done by running them through a debugger), and the great majority of them are written in C++.

When NSA realized they had to implement their secret Skipjack encryption algorithm in software because of limited manufacturing capacity for hardware crypto devices, they decided to publish full specifications for the algorithm before it got reverse-engineered by someone else.

Count yourself lucky if your competitors waste time trying to reverse-engineer your app instead of just coding their own rip-off from scratch. If you got an algorithm really worth protecting then don't trust code obscurity to keep it safe, get a proper patent.

[edited by - HenryAPe on July 11, 2003 4:58:54 AM]

Share this post


Link to post
Share on other sites
CaptainJester, that may be the simplest way of obfuscation, but if you want to make it hard for people who decompile your code the get a demo of an obfuscator and use it. It''s much harder to underand code that uses one. And yes, I agree with HenryApe, if you really want to protect your algorithm, just get a patent. And expanding on rickwinter''s post, the program Excepsior JET can create native exe''s from java code. It optimizes it beautifully too. You can get a demo, I don''t remember off the top of my head what the limitations are though. For the professional edition demo it''s a 60 day trial, for the non professional edition it never expires, I can''t remember the draw back. Anyway, for any of you interested, the site is http://www.excelsior-usa.com/jet.html.
And also, in case any of you are wondering the rough size of the exe it creates, I made a hello world program with a few other functions in it and it came to 10kb or so. Anyway, enough of my talking.

Share this post


Link to post
Share on other sites
I agree. If you're really paranoid about people stealing your ideas, run your source through a freeware obfusicator. But I'd think that anyone tenacious enough to tackle optomized-decompiled source won't be stopped by cheap or free obfusication. In a world with Intigrated Reverse-Engineering Enviroments, any code you write can be read by others in one form or another. If you want to protect it, write it on a napkin and hide it under your tower.

I guess the real question to you Telamon is what is the major platform you want to distribute to? (and what's so secret about your algorithms?)

[edited by - Infinity_ on July 11, 2003 6:15:09 AM]

Share this post


Link to post
Share on other sites