If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

well it takes a lot of work to make it into a (windows) executable but what i usually do is write batch files instead compiling in the dos prompt a sample batch file could look like this:

Code:

@echo off
cd..
cd my_application
javac calc.java
pause
java calc

first line does not display the commands typed by the batch files, only runs the commands
second line just takes you down one level in your directory files, usually in windows u start in the folder c:/windows/ so the cd.. makes u go to c:
third line then goes to the folder my_application (change this to whatever your folder is called)
fourth line compiles yoru code
fifth line types "please press a key to continue" on screen and waits for user input
fifght line runs your java application

type this code in notepad or some such text editor and be sure to safe it as "filename.bat" dont forget the quotes if you use notepad.

nice nice, I see what you mean. so the batch file would be doing everything the user would normally have to do. That is an excellent an idea. But I wouldnt be able to run this batch file from just any folder, it would have to be the bin correct? I ask this because if I try to javac within another folder, i cant do it. But I would be able to java it from another location correct? So in my batch would I put the javac command or can i just put "java prog name" as long as the java class file is in the folder?

have you changed your autoexec.bat file to include the path to your java compiler? your autoexec.bat file is usually just in your c drive (not in a folder). if u dont have a autoexec.bat file then you should make one and inside it add a line like this:

Code:

path=%path%;c:\j2sdk1.4.1\bin

in my case my java compiler is in teh folder j2sdk1.4.1, change this to wherever your compiler is located. also when you change your autoexec.bat file you have to restart before it takes effect. when you have restarted you can call javac from any folder in your computer.

JAR

and if anyone didn't tell you how to make an Executable Jar file, or you dont' know how to make one, it's like this:
@ the command prompt type:
jar -cfm <name of output jar file> <name of manifest file> <classes or anything to include>
there are spaces, ok, between each argument.
- the output jar file is any name you want your jar file to be.
-the manifest file is the file which contains the name of the class which contains the main method. just make a file of any name with this in it: Main-Class: <name of class with main method>
-the last one in this example is what you want in the jar file. you could do *.class or *.*, and jar will automatically include all classes in current folder,or all files, respectively. or you could specify MyClass.class, etc., that depends on you.
Actually, you could do more with jar files, than just make them execute your java program without a dos command window opening up everytime, and making your desktop look cluttered.

Hello,
I created a jar file from one of my programs... When i try to open it using "javaw" or whatever.. it Says "Could not find main class." What is wrong? I am also comfused by when you say "manifest"... What does that mean? Thanks.

jar cf nameOFprog.jar nameOFprog.java *.class and it created the jar file. I tried it the way you told me, and it said i had an error that looked like this
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:351)
at java.util.jar.Manifest.read(Manifest.java:162)
at java.util.jar.Manifest.<init>(Manifest.java:52)
at sun.tools.jar.Main.run(Main.java:124)
at sun.tools.jar.Main.main(Main.java:904)

I have my jar file now, but it wont open when i double click on it. what is wrong?

There is a free ( personal use only ) Java compiler out there. I've not used it yet, so can't really comment much. Besides, the whole point with Java is its portability but if anyone wants to try it.....

don't forget the m coz it tells jar that you are including a manifest file.

<output file> must have jar as an extension or it won't run

manifest is simple. just open any text editor program and place this inside:

Main-Class: <name of class with the main method>

don't place the .class extension in the name of the class file with the main method. if the class is Main.class, jsut place Main. only the class with the main method is required in the manifest file. no other class is needed.
if the Main-Class ( with first letters in capital ) keyword is not being accepted, try Main-class ( this is with a small letter c in class ) or main-class. i am not so sure anymore coz i haven't used jar in quite a while already. so just experiment until it comes out ok. ok? but the first thing that comes into mind is really Main-Class. then save it with any name. i don't ust an extension. i just type in a name like Manifest or one that's associated to a program i making a jar file for.

also, you don't have to include your java source codes ( *.java files ) in a jar file for it to be executable. all it needs to become an executable jar file are the class files. all class files that a particular program needs, so be sure everything is in the jar file. try *.class (wildcards) so you won't have to enumerate all the classes.

again java is case sensitive so make sure you get the names correctly.

and to open a jar file just click the icon of your jar file. you need not open a command prompt. if you want to open a jar file in DOS, don't use javaw. instead, use java -jar <name of jar file>.

to Joyous Monkey

got a nice nick for a moderator. i thought moderators had serious nicks.

anyway, ya, java's edge over other langs is it's portability. but the thread starter was saying something like he's tired of always opening DOS and typing java **** to start a program. so using a batch file or a jar file is one way of doing away with the DOS prompt, etc.

to Joyous Monkey

got a nice nick for a moderator. i thought moderators had serious nicks.

anyway, ya, java's edge over other langs is it's portability. but the thread starter was saying something like he's tired of always opening DOS and typing java **** to start a program. so using a batch file or a jar file is one way of doing away with the DOS prompt, etc.