Solved

Need help going from code to an executable

Posted on 2004-10-15
12
174 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 134
looking for unix program to search some keywords in side EAR WAR and JAR files 10 82
couple of eclipse 5 27
servlet example issue 6 33
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

863 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

22 Experts available now in Live!

Get 1:1 Help Now