Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javac Command  RSS feed

 
Chandu Neni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac -classpath /tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/QuoteServlet.java

Could any one please explain me what the :classes:. signify?

Thanks in advance.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Entries in the "classpath" represent *.jar files or directories. In your example, "classes" appears to be a subdirectory of the working directory. Javac will search for class files there, and the new files it produces will be placed there (because of the "-d" switch.)
 
Chandu Neni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for ur instant reply.

I am not still clear about it.

javac -classpath /tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/QuoteServlet.java

In the above command "-classpath /tomcat/common/lib/servlet-api.jar:classes:. ", does it mean the javac will look for classes in servlet-api.jar and also classes dir in .(current dir)
What does :classes:. notation exactly mean?

Thanks in advance.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The : is a separator between different parts of the path. ':' is the path separator on Unix systems, while for Windows it would be ';'. Anyway, with a classpath of

/tomcat/common/lib/servlet-api.jar:classes:.

that splits into three parts, separated by ':'.
  • /tomcat/common/lib/servlet-api.jar
  • classes
  • .
  • What that means is, when javac needs to find a particular class, first it will search the servlet-api.jar, then it will search the classes directory, and then it will search the current directory. (Because '.' is a special symbol for the current directory.)
     
    Chandu Neni
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Jim,

    Its crystal clear now. Didnt know : is a seperator in Unix like ; is in windows.

    Need a little more clarification on javac -classpath..

    if there is a environment variable classpath set, will javac look for the classes both in the classpath set in the environment variable and also given as a flag (-classpath) in the command or does it only look in the flag and ignore environment variable.

    Thanks a lot.
     
    Jim Yingst
    Wanderer
    Sheriff
    Posts: 18671
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If the -cp or -classpath options are used, any CLASSPATH environment variable is ignored. The place to find this info is in the javac and java documentation, found under tools and utilities in the JDK documentation.
     
    Chandu Neni
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks once again Jim.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!