Solved

Need help going from code to an executable

Posted on 2004-10-15
12
181 Views
Last Modified: 2010-03-31
Hi all,

ok I've finished my first ever Java application (thanks in no small part to people's help on this website!).  I have been developing using JBuilder and running it through that.

Now I just need to put it in a form where other people can use it, but i have no idea about how to do this!  Could people please give me a walk through of how to turn my code into a file which I can email to people and they can run?  Hopefully this is fairly straightforward task, if not I'll up the points!
0
Comment
Question by:agrees
  • 7
  • 5
12 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 175 total points
ID: 12318976
I JBuilder, do:

File->New->Build->Archive Builder

Select "Executable Archive", and fill in your main class..  Then it should generate a jar file you can double click on (in windows) or run like:  java -jar nameofjar.jar
0
 

Author Comment

by:agrees
ID: 12319193
Hmm I've only got JBuilder foundation and so apparently creating executable archive isn't available.  Any way round this?  If not I can probably download the trial version of developer (I'll probably have to do it onto another PC because i've already done it once on this one)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12319314
Inside "Archive Builder"

It's called "Application" under the "Archive Type" drop down...

That's missing in JBuilder foundation?

Bah!

This show you what it basically does:

http://www.cs.princeton.edu/introcs/85application/jar/jar.html
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:agrees
ID: 12319583
Ah right no that's working - I didn't realise you had to do a build before it generated the .jar file!

Ok I think that's pretty much it.  Just one thing: I've tried to run the file on another PC and it is asking what program it should run on - is this just because that PC doesn't have a JVM?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12319667
yeah...  installing the jvm should sort that out :-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12319692
there is a problem that some things like WinZip and WinRAR if installed after the JVM will "steal" the file extension ".JAR" and so they will open it rather than java running it...

What you can do, is deploy a batch file along with your JAR file, so people can double click on the batch file and that does

java -jar yourjarfile.jar

Then that will work no matter what (so long as they have the JVM and "java" on their path) ;-)
0
 

Author Comment

by:agrees
ID: 12320580
Hmm well the sun JVM installation won't work so I'm downloading Microsofts JVM instead.

I've added 50 points because I have another related question!  The application uses some resource files (.jpg, .wav and .txt).  What is the best way to associate these with the application?  Is there a way to get a relative path?  At the moment I just have the full pathname in like this:

  private static final String baseURL =
      "file:C:/Documents and Settings/Administrator/jbproject/strategySimulator/src/sounds/";

  private static AudioClip MOVE = Applet.newAudioClip(new URL(baseURL + "water.wav"));;

     
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12320723
>  Hmm well the sun JVM installation won't work so I'm downloading Microsofts JVM instead.

!?!?!

Microsoft's JVM (if you can find it) only works with Java 1.1, as they stopped supporting it :-(  What was wrong with Sun's one?

private static AudioClip MOVE = Applet.newAudioClip( ThisClass.class.getResource( "/sounds/water.wav" ) ) ;
0
 

Author Comment

by:agrees
ID: 12321127
I should have said, I have non static uses too so getResource() won't work (will it?)  For example here I create a new audioclip and play it in a new thread, and it throws a null pointer if I use getResource()..

  public static void playThreadedSound(final String file) {
    Thread playerThread = new Thread(new Runnable() {
      public void run() {
        AudioClip newClip = Applet.newAudioClip(Sounds.class.getResource(file)); // get null pointer here
        newClip.play();
      }
    });
    playerThread.start();
  }

I also want to read and write from a text file, which saves data when an application is closed and re-loads it when the application is started.  Like this:

   try {
      BufferedReader in = new BufferedReader(new FileReader(FILES +
          "strategies.txt"));
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12321763
       AudioClip newClip = Applet.newAudioClip(Sounds.class.getResource(file)); // get null pointer here

is the "file" variable being passed:  "/sounds/whatever.wav"?

That should work...

is "whatever.wav" in the jar file inside the "sounds" directory?

Tim
0
 

Author Comment

by:agrees
ID: 12346135
Sorry for the delay I got dragged away over the weekend!  Thanks for your help Tim, I still have 1 final thing to sort out but I've put that in a new question here:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21173655.html
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12346228
Glad I could help :-)

Looks like people have pretty much answered your other question (you can't, you will have to save the file outside the jar)

Good luck with it :-)

Tim
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now