커맨드라인에서 javac 컴파일 해보기

커맨드라인에서 javac 컴파일 해보기

이클립스에서 대부분 해주기때문에 크게 신경을 쓰지 않지만, 기본적인 사용법을 잠깐 살펴보기로 하자.
기본적으로 사용할때는 javac 자바파일이면 되지만, 서블릿등에서는 추가적인 라이브러리(*.jar)를 지정해줘야 한다.

D:\workJSP\ddit\src>javac org\ddit\web\util\CookieBox.java
org\ddit\web\util\CookieBox.java:9: package javax.servlet.http does not exist
import javax.servlet.http.Cookie;
                         ^
org\ddit\web\util\CookieBox.java:10: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
                         ^
org\ddit\web\util\CookieBox.java:12: package org.apache.tomcat.util.buf does not exist
import org.apache.tomcat.util.buf.UDecoder;
                                 ^
org\ddit\web\util\CookieBox.java:15: cannot find symbol
symbol  : class Cookie
location: class org.ddit.web.util.CookieBox
        private Map<String, Cookie> cookieMap = new HashMap<String, Cookie>();



겁나게 많은 컴파일 오류를 볼 수 있을것이다.

why? 추가적인 라이브러리를 명시해주지 않았기 때문에
기본적으로 환경변수 PATH등에 저장해줘도 되지만,
-classpath나 -cp 옵션등으로 jar파일을의 위치를 지정해주면 된다.


D:\workJSP\ddit\src>javac -cp “C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar” org\ddit\web\util\CookieBox.java


D:\workJSP\ddit\src>javac -cp “C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar” org\ddit\web\util\CookieBox.java -d ..\build\classes


 


D:\workJSP\ddit\build\classes\org\ddit\web\util



윈도우즈에서 javac 컴파일 옵션
D:\workJSP\ddit\src>javac -help
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>…]Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system

Leave a Reply

Your email address will not be published. Required fields are marked *