My brother was asking me to make a little program for him to help him with working on pictures, that would find all the coordinates of a certain color in an image. I was able to make the program itself fairly quickly, but I'm just looking to make it a .jar so he can use it on his computer, instead of only me being able to run it in my DrJava.

How can I do this?
My friend brags about Dr. Java being able to make .jars. I'd try looking through some menus for that.

Edit: Project > Create Jar from Project
For what it's worth, a jar is basically a compressed archive of java files. Smile
Can't you make it executable, though?

Btw, _player, I figured out how to make a .jar using it, but I ran into what Kerm was saying, and when I double click it, it won't run, but WinZip will open it as an archive.
It should be instantly executable.
Code:
java -jar your.jar
will run it. You could write a quick program to do
Code:
system("java -jar blah.jar");
Though, if you look online, I'm sure you can find a .jar -> .exe converter. Also, a .bat with "java -jar your.jar" would work, too, (and wouldn't involve C...).
You can normally just double-click a .jar file and it'll run it (at least on Windows, and as long as some other piece of software hasn't stolen the .jar association from the JRE as WinZip appears to have done in your instance). Either reinstall the JRE or re-associate .jar files with it (Jarfix purports to be able to perform this task for you easily).
When compiling it to a .jar, I'm seeing I can make it an executable if I have a main .class file for it, but I only have a .java and a .drjava. Ideas?
You compile the .java to a .class file. Then you use the jar program included with the Java SDK and compress the .class file into a jar file. That said, is there any particular reason a .class file won't work for this situation?
Wouldn't the end-user have to know how to use a command line and get to the right directory and then use "java blah.class"? Rather than just being able to double click the icon and/or say "Run with Java".
Qwerty.55 wrote:
You compile the .java to a .class file.
How?
That could be done pretty easily with a .bat file (which is double click executable) or just assigning the .class file to java. .jars aren't really necessary for a lot of applications because of the whole mess with signing and verification.

Code:
javac blah.java


Edit: Yeah, I still think a .bat would be best for something like this.
Tick the "Make executable" box, I guess.
run.bat:

Code:

javac RGBSearch.java
Pause


Returns:

Code:

C:\Java files\RGBSearch>javac RGBSearch.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\Java files\RGBSearch>Pause
Press any key to continue . . .



benryves wrote:
Tick the "Make executable" box, I guess.
I'd love to, I just don't have a .class file for my program, or at least don't know which I should use.
`javac' is used to compile the .java file. You have DrJava, so let it compile the program. And then just give your friend a .zip with the: .class and a .bat (containing "java blah.class"), and let him unzip it and run the .bat.
You probably don't have javac in your PATH.
You might have to cd to the directory containing javac and use the full path for the .java file.

Also, your run.bat would contain the text "java RGBSearch.class" to execute the compiled .class file. Compilation is only necessary once.
Oops, just realized, you don't use ".class". So it would really be "java RGBSearch".
I don't see what's so tricky about building a jar rather than faffing around with DOS batch files.



In DrJava, click Project -> Create Jar File from Project, set it to Jar your classes, Make executable, enter the name of your main class, give it an output path and you should be done.
Umm, I did this once..

To compile something type"javax [file-to-compile]" it will compile your program. Remember to type the full name of the file. (eg. "foo.java" in stead of "foo")

Create a file called "manifest.txt" in the folder with your .class files. In it type:

Main-Class: MyMainClass

Then push enter. MyMainClass is the class with the main method. Type "jar cvfm MyJar.jar manifest.txt *.class" at whatever shell you use. You will now have an executable jar.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement