Solved

Need help going from code to an executable

Posted on 2004-10-15
12
163 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countHi2 challenge 7 44
What is the latest versions eclipse neon 2 122
eclipse java  build path 6 21
GUI builder for Eclipse? 8 11
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

759 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

24 Experts available now in Live!

Get 1:1 Help Now