Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

-classpath command  RSS feed

 
carl summerfield
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

With a Windows 2K operating system and jdk6u2, I am attempting to compile HelloWordApp.java. There is no autoexec.bat file in Windows2K, however at least two options appear to exist for initiating a compile, one from the command line using -classpath, and the other with an environmental variable.

If the path to the \bin directory is
c:\program files\Java\jre1.6.0

and HelloWorldApp.java is located here
d:\javasrc\HelloWorldApp.java

what should the -classpath command line look like for compilation?

Thanks, carl

This message was supposed to go to the Beginning Java Forum, but from the current screen, no options are available, appoplgies if my text is directed to another forum.
 
Vijayender Bandaru
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please spend some time to read Sun's Java tutorials.

http://java.sun.com/docs/books/tutorial/getStarted/problems/index.html
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carl,

Welcome to JavaRanch.

what should the -classpath command line look like for compilation?

javac -cp <path> MyApp.java
or
javac -classpath <path> MyApp.java

Just type javac in your shell/command prompt and you can see the list of options available. The same thing with java command.
[ August 07, 2007: Message edited by: Freddy Wong ]
 
carl summerfield
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijayender,

Thanks for the link, but could not find anything on -classpath there. Could you please be sure this is the page to which you intended to send me.

thanks again, carl
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by carl summerfield:
Vijayender,

Thanks for the link, but could not find anything on -classpath there. Could you please be sure this is the page to which you intended to send me.

thanks again, carl



Here's another page that talks about it:
http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/classpath.html

In your orginal post you said
If the path to the \bin directory is
c:\program files\Java\jre1.6.0


Unfortunately I don't have a Windows system with Java installed and I could be wrong, but I thought that javac.exe (the compiler) was put in some directory that had "jdk" in the path, not "jre".
[ August 07, 2007: Message edited by: Red Smith ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

you should not need to set a classpath.

Java can find the API classes itself, and the classpath defaults to the current directory for classes you've compiled yourself. So if your .java file is at d:\javasrc\HelloWorldApp.java, then change directories (cd) to that location, and compile and run from the command prompt as follows...

>cd d:\javasrc
>javac HelloWorldApp.java
>java HelloWorldApp

(For reference, here's the page that Red posted, except for version 6 running on Windows: Setting the class path.)
[ August 07, 2007: Message edited by: marc weber ]
 
carl summerfield
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Red Smith:


Unfortunately I don't have a Windows system with Java installed and I could be wrong, but I thought that javac.exe (the compiler) was put in some directory that had "jdk" in the path, not "jre".

[ August 07, 2007: Message edited by: Red Smith ]


Red,

You are correct, jre not the same as jdk, will download, and hopefully everything will be OK.

Thanks for pointing out my error, carl
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!