Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help going from code to an executable

Posted on 2004-10-15
12
Medium Priority
?
205 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 700 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

688 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