Results 1 to 6 of 6
- 02-03-2009, 02:07 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
- 02-03-2009, 05:22 PM #2
A few things.
First, you want to run the "java" or "javaw" command.
Second, that command requires an option that defines the classpath, which tells "java" where to find classes.
Third, "java" works with .class files, not .java. You have to compile the .java files into .class files.
- 02-04-2009, 02:40 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Basically think about the steps you have to follow, working on with the command prompt.
First of all you have to set the class path. On the command prompt you can do that as follows on the working folder.
Depends on the Java installation path the version, the above command can change.path=C:\Java\jdk1.4\bin\
Then you have to compile the Java class.
Then run the class, that's what Steve clearly explain. You cannot run the *.java file. Only *.class file can run.javac MyClass.java
- 02-05-2009, 03:04 PM #4
I hate to nitpick, but...
path=C:\Java\jdk1.4\bin\
sets the system path for finding programs, not the classpath. You need to set the "classpath" environment variable. You can also specify that on the "java" command using the "-cp" option.
One more thing. You should *not* be working in the JDK's "bin" directory, or in any directory of the JDK. Set up a separate directory structure for your stuff.
- 02-06-2009, 07:22 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 02-06-2009, 07:49 AM #6
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
c:/j2sdk1.4.0/bin/helloworld.java is not a recognized executable by windows. '.java' files are not executable, and windows does not recognize "/", it uses "\".
If you can't run it by typing it into 'run' from the start menu, then Runtime.exec isn't going to be able to run it either.
First you need to run javac on your 'helloworld.java'. Assuming you did that in c:\j2sdk1.4.0\bin (which is generally a bad idea, but since you're learning...), then the command you would use in Runtime.exec woudl be something like
"c:\\j2sdk1.4.0\\bin\\java -cp c:/j2sdk1.4.0/bin helloworld"
Java uses "/" notation, which is why this seems all mixed up.
Similar Threads
-
executing external programs
By Levish2002 in forum AWT / SwingReplies: 0Last Post: 09-10-2008, 07:04 PM -
help-executing the program
By j2vdk in forum New To JavaReplies: 6Last Post: 08-30-2008, 09:18 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM -
Use a external file in my program
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks