Solved

Need help going from code to an executable

Posted on 2004-10-15
12
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

623 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