User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,518 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,831 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1660 | Replies: 17
Reply
Join Date: May 2005
Location: India
Posts: 65
Reputation: vicky_dev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vicky_dev's Avatar
vicky_dev vicky_dev is offline Offline
Junior Poster in Training

Question Running Java Program outside an IDE

  #1  
Oct 3rd, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: Adelaide, South Australia
Posts: 428
Reputation: darkagn will become famous soon enough darkagn will become famous soon enough 
Rep Power: 3
Solved Threads: 53
darkagn's Avatar
darkagn darkagn is offline Offline
Posting Pro in Training

Re: Running Java Program outside an IDE

  #2  
Oct 3rd, 2007
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...
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,166
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 59
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Running Java Program outside an IDE

  #3  
Oct 3rd, 2007
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
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Apr 2006
Location: City of God
Posts: 163
Reputation: orko is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: Running Java Program outside an IDE

  #4  
Oct 3rd, 2007
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.
A Perfect World
Reply With Quote  
Join Date: Feb 2006
Posts: 1,512
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Running Java Program outside an IDE

  #5  
Oct 3rd, 2007
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Sep 2007
Posts: 27
Reputation: schoolsoluction is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
schoolsoluction schoolsoluction is offline Offline
Banned

Re: Running Java Program outside an IDE

  #6  
Oct 3rd, 2007
Originally Posted by masijade View Post
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).
Reply With Quote  
Join Date: Feb 2006
Posts: 1,512
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Running Java Program outside an IDE

  #7  
Oct 3rd, 2007
Originally Posted by schoolsoluction View Post
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: May 2005
Location: India
Posts: 65
Reputation: vicky_dev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vicky_dev's Avatar
vicky_dev vicky_dev is offline Offline
Junior Poster in Training

Re: Running Java Program outside an IDE

  #8  
Oct 4th, 2007
Originally Posted by masijade View Post
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
system("java app.class");
in the code. But then how do I get the right path for Java.exe?
Reply With Quote  
Join Date: May 2005
Location: India
Posts: 65
Reputation: vicky_dev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vicky_dev's Avatar
vicky_dev vicky_dev is offline Offline
Junior Poster in Training

Re: Running Java Program outside an IDE

  #9  
Oct 4th, 2007
Originally Posted by masijade View Post
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.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,512
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Running Java Program outside an IDE

  #10  
Oct 4th, 2007
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 4:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC