Easy way to distribute .class java files?

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
I've been learning Java for about 5 months or so in school and also at home. Right now its just command line and applets.

Is there some easy way I can use a program that will modify my command line version or something so that if I send the program to a person with just java installed and without knowing how to use the command prompt to run?

Basically, I'm looking for a simple way for the average person to run a java file I made without learning the command prompt. The ideal program would be one that turns it into a .exe file and all the user has to do is double click on it and use it. I don't care if it still shows a command line and all, but I basically want it to be as easy as possible for the end user to run.
 

Gibson12345

Member
Aug 31, 2002
191
0
0
Bad news: Unless you compile your Java into Native (and there are compilers that will do it), your users need to have the Java runtime installed.

Good news: You can write a batch file to run your program in about four seconds. Open Notepad and write whatever shell command you use to run your program (probably just "java myprogram"), and save the file as Whatever.bat. Then just double click the batch file to run your program. .jar files (Java archive) can also be made executable, but that has to be enabled on the end-user's machine, so batch files are probably a better solution.
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
Thanks, that helps.

Another question: Is there some way I can do something like this:?

java http://www.websitehere.com/filename

This way all they have to download is the .bat file. It basically makes it simpler in that they won't have to download multiple files or a zip file and extract, all they would have to download would be a .bat file and run it.
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
Create a .jar file for your application, and then create a very basic C/C++/VB program that issues the shell command "java -jar myJar.jar";

Then your users can double click on an exe file, just like normal, and they won't have a command prompt hanging around in the background either. Basically it will give the illusion that its a real compiled native application, even when it isn't.

The other option is if you are only aiming at Windows users, you can use MS's J++ to create an .exe of your application. It isn't native code, its basically the Executable wrapper I describe above along with the embedded .class files, but it looks nice.
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
Kilrsat, can you give me links or something like a tutorial?

If you know how to make that program, is it long, if not, could you so kind as to write it for me? I've had experience with other languages but I don't think I'd have enough knowledge for writing any other types of programs yet.

So wait, is your solution saying that they will just have to download one file, double click it and run?

Also, if I want it to work for just windows users, how exactly do I make that exe?

Gibson, how do I compile into native?
 

manly

Lifer
Jan 25, 2000
13,303
4,082
136
Originally posted by: Centinall
sorry, but i don't know much about this subject, but isn't Java Web Start an option too?
Yes.

A JAR file would be easy for beginners though.
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
A jar file is probably the best, but if you want to customize it a little more, you can download an NSIS (the Nullsoft installer) script to create an exe wrapper around the jar file. The exe wrapper will check for Java runtimes and notify the user if they don't exist. Also, you can set a custom icon.
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
Originally posted by: igowerf
A jar file is probably the best, but if you want to customize it a little more, you can download an NSIS (the Nullsoft installer) script to create an exe wrapper around the jar file. The exe wrapper will check for Java runtimes and notify the user if they don't exist. Also, you can set a custom icon.

I'll look into this. Thanks :D
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
Edit: I have found a tool for taking .jar files and making them into an executable file.

How do I create a .jar file though?
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
'jar' is not recognized as an internal or external command,
operable program or batch file.

I get that error when I try to use the "jar" command
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Did you add your java directory to your PATH yet? Do the "javac" and "java" commands work?
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
java works, but javac doesn't. For writing/compiling I use textpad which does that for me. I don't think javac is defined. How do I do that?
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
You're supposed to add the path to your java SDK bin folder to your PATH variable. I'm assuming that you're using WinXP.

You would go to Control Panel -> System -> Advanced -> Environmental Variables.
Under PATH for either your profile or the system, add the folder path to your Java SDK bin folder. Mine is "C:\j2sdk1.4.2_02\bin". Make sure it's separated from the rest of the directories with a semi colon. If there's a space in the path, put quotes around it.

I think the java command works because of the Java runtimes.
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
Originally posted by: igowerf
You're supposed to add the path to your java SDK bin folder to your PATH variable. I'm assuming that you're using WinXP.

You would go to Control Panel -> System -> Advanced -> Environmental Variables.
Under PATH for either your profile or the system, add the folder path to your Java SDK bin folder. Mine is "C:\j2sdk1.4.2_02\bin". Make sure it's separated from the rest of the directories with a semi colon. If there's a space in the path, put quotes around it.

I think the java command works because of the Java runtimes.

Thanks igowerf! :D

It all works now and I can create executable java files! :)

One more question, how do I compile to native and is it soemthing that will be able to run on a computer without java?
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
I don't know how to compile to native. I have a feeling that doing something like that would make your program really big. You still need the runtime files to run your program.

The best you can do is to create a wrapper exe around the jar file and have the exe file inform the user if he or she needs to download the runtimes.

I used Jelude. It sort of creates an installer that runs your jar file. To the user, it's just another exe file though. You can customize the icon. If the user doesn't have the JRE's, a popup dialog will inform them.