943,626 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4662
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 3rd, 2007
0

Running Java Program outside an IDE

Expand Post »
Hi everyone, I need to be able to run a Java application (not an applet) directly, that is not from an IDE or the command line. How can this be done for a Windows PC? I have seen many applications written in Java, but are executed just like other Windows apps, so there must be a way.
Reputation Points: 28
Solved Threads: 2
Junior Poster in Training
vicky_dev is offline Offline
86 posts
since May 2005
Oct 3rd, 2007
0

Re: Running Java Program outside an IDE

In your command line prompt type java myProgram to run a compiled version of a java program called myProgram. You may need to set an environment variable for the path where your java vm is installed. Let us know if you need to know how to do this...
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Oct 3rd, 2007
0

Re: Running Java Program outside an IDE

javaw is designed for that (launches the JVM but without a command window) again needs to be in your path. Then create a windows shortcut with the necessary command. See here for more info:

http://java.sun.com/j2se/1.4.2/docs/...dows/java.html
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Oct 3rd, 2007
0

Re: Running Java Program outside an IDE

To compile the code you have to type:
javac myapp.java
it will create a myapp.class file in the same or diff location... then just follow it and type java myapp it will run the code... you have to compile before running... you may have to setup the classpath to include your JRE in your environment... you can follow this:
go to Start menu-> My Computer (right button click) select Properties -> Advanced ->Environment Variables-> CLASSPATH click on Edit, and set the path location of your jre... typically it is under Program Files/Java/jre1.x.0_xx here x is some number.
Reputation Points: 46
Solved Threads: 11
Junior Poster
orko is offline Offline
164 posts
since Apr 2006
Oct 3rd, 2007
0

Re: Running Java Program outside an IDE

Once you install Java, you should be able to "double-click" on a .class file and execute it in that way, if you don't have a class file (but just a .java file), then you have to compile it/them first. Better would be, to create a jarfile containing the relevant classpath info and such in the Manifest file so that every thing is handled correctly, and then "double-click" that jarfile.

Obviously.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Oct 3rd, 2007
0

Re: Running Java Program outside an IDE

Click to Expand / Collapse  Quote originally posted by masijade ...
Better would be, to create a jarfile containing the relevant classpath info and such in the Manifest file so that every thing is handled correctly, and then "double-click" that jarfile.

Obviously.
Best is to use ANT to build your projects to jar files. (or maven if you want to take it a step further).
Reputation Points: 30
Solved Threads: 3
Light Poster
schoolsoluction is offline Offline
27 posts
since Sep 2007
Oct 3rd, 2007
0

Re: Running Java Program outside an IDE

Best is to use ANT to build your projects to jar files. (or maven if you want to take it a step further).
Once you know how to do it manually, yes. But just like with using an IDE, you should not start with it. You should first learn how to do it manually, so you understand what is happening.

That said, what real difference does it make what tool he uses to build the jarfiles (once he understands what is happening, anyway)?

Making a jarfile was not suggested only for convenience (which the ANT suggestion was). It could be, and probably is, a very real necessity, if any third party libraries are involved.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Oct 4th, 2007
0

Re: Running Java Program outside an IDE

Click to Expand / Collapse  Quote originally posted by masijade ...
Once you install Java, you should be able to "double-click" on a .class file and execute it in that way, if you don't have a class file (but just a .java file), then you have to compile it/them first.
No, it is not so on my system. The .class does not have an association with any program and isn't opened. I have to select the program I want to open the .class file with.

What I'm actually looking for is a normal windows EXE file, which when executed launches the Java application. Maybe I can use something like
Java Syntax (Toggle Plain Text)
  1. system("java app.class");
in the code. But then how do I get the right path for Java.exe?
Reputation Points: 28
Solved Threads: 2
Junior Poster in Training
vicky_dev is offline Offline
86 posts
since May 2005
Oct 4th, 2007
0

Re: Running Java Program outside an IDE

Click to Expand / Collapse  Quote originally posted by masijade ...
Better would be, to create a jarfile containing the relevant classpath info and such in the Manifest file so that every thing is handled correctly, and then "double-click" that jarfile.
Well a .jar file open with WinRAR on my system! It seems that jarfiles are like a collection of zipped .class files.
Reputation Points: 28
Solved Threads: 2
Junior Poster in Training
vicky_dev is offline Offline
86 posts
since May 2005
Oct 4th, 2007
0

Re: Running Java Program outside an IDE

You have done something that has changed the file associations on your machine. (For the jarfile one it was the installation of WinRAR.)

Change them back.

.class should be opened with "java" or "javaw" and .jar should be opened with "java -jar" or "javaw -jar". Alternatively, you could de and re install java and let it reset the file associations itself.

Edit: And java.exe (or javaw.exe) should already be in your path if java is properly installed. If not, add the directory containg them to your path, obviously.

All of these things, BTW, are System Maintenance questions, and not Java questions, per se.

Edit Again: All of these, BTW again, would also be non-issues, if you had learned Java the right way, rather than learning it using an IDE (which is really only learning to use the IDE and not learning Java, as illustrated by these questions).
Last edited by masijade; Oct 4th, 2007 at 10:22 am.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Need Help.. please? :D
Next Thread in Java Forum Timeline: abstract class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC