달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2011. 1. 5. 11:14

javac, java 명령어의 옵션 Enjoy/JAVA2011. 1. 5. 11:14

출처 : http://silmelove.blog.me/30015264341


자바 컴파일과 실행 에 사용되어지는

 javac, java 명령어의 옵션을

다음과 같이 정리하였습니다.


javac - 자바컴파일러로써, 자바코드를 작성한 소스파일(.java)을 자바 가상머신이 인식할수 있는 바이트 코드(.class)
타입으로 변환시켜주는 명령어 입니다.

사용법: javac <options> <souce files>
예를들어, Hello.java, Greeting.java 두개의 파일이 존재한다면,
javac Hello.java Greeting.java
javac *.java (*을 사용해서, 모든 확장자가 .java인 파일을 컴파일할수 있다.)

 

1) 옵션:


a) -classpath:

 -classpath(cp) path(파일 절대 경로):
 컴파일러가 컴파일 하기 위해서 필요로 하는 참조할 클래스 파일들을 찾기 위해서 컴파일시 파일 경로를 지정해주는
옵션. 예를 들어,  Hello.java파일이 C:\Java 디렉터리에 존재하고, 필요한 클래스 파일들이 C:\Java\Engclasses에 위치한다면,
javac -classpath C:\Java\Engclasses C:\Java\Hello.java 로 해주면 된다. 만약 참조할 클래스 파일들이 C:\Java\Engclasses외의 
다른 디렉터리에도 존재한다면, C:\Java\Korclasses 일경우, 
javac -classpath C:\Java\Engclasses;C;\Java\Korclasses C:\Java\Hello.java
그리고, 현재 디렉터리역시 포함하고 싶다면,
javac -classpath .;C:\Java\Engclasses;C;\Java\Korclasses C:\Java\Hello.java
기본적으로, dos에서는 .는 현재 디렉터리를 의미하고, ..는 현재 디렉터리의 상위디렉터리를 의미한다. 
또한 classpath 대신 단축어인 cp를 사용해도 된다.
javac -cp C:\Java\Engclasses C:\Java\Hello.java 

 

b) -d: 
 -d directory
 클래스 파일을 생성할 루트 디렉터리를 지정합니다.
기본적으로 컴파일러는 -d옵션을 주지 않으면, 소스파일이 위치한 디렉터리에 클래스 파일을 생성시킵니다.
예를 들어,  Hello.java파일이 C:\Java 디렉터리에 존재하고 클래스 파일의 루트디렉터리를 C:\Java\Classfiles라고 하면, 
javac -d C:\Java\Classfiles C:\Java\Hello.java 입니다.

만약 -d 옵션을 사용하려고 하는데, 루트디렉터리(위예에서는 C:\Java\Classfiles) 가 존재 하지 않는다면, 
"The system cannot find the path specified"라는 에러 메시지를 보게 됩니다. 
현재 작업 디렉터리가 C:\Java\Classfiles 에 위치하면, 
javac -d .\Classfiles Hello.java 와 같이 상대 디렉터리로 표현할수 있습니다.

java class내에서 package를 선언한 경우 package별 폴더를 생성하고 해당 폴더에(package) compile한다.

 

c) -encoding:
-encoding encoding name
소스 파일에 사용된 문자열 인코딩을 설정합니다.
만약 위옵션이 설정되어 있지 않으면, 플래폼의 기본적인 컨버터가 사용되어 집니다.

 

d) -g:
모든 디버깅 정보를 생성시킵니다.
만약 위옵션이 설정되어 있지 않으면, 기본적으로, 라인넘버만 생성시킵니다.
-g:none: 디버깅 정보를 전혀 생성 시키지 않습니다.
-g:{lines, vars, source}:
위처럼 명시적으로, 몇몇 디버깅 정보를 생성시킬수 있습니다.
lines은 라인정보, vars는 지역변수, sounce는 소스 파일 정보를 나타냅니다.

 

e) -nowarn:

경고 메시지 (warning message)를 생성시키지 않습니다.

 

f) -verbose:

컴파일러와 링커가 현재 어느 소스파일이 컴파일되고 있고, 어느 파일이 링크되고 있는지 
그정보를 출력한다.

 

h) -deprecation:

소스 코드내에서, 사용되어진 deprecated API의 위치 를 출력 합니다.

ex)
C:\Java> javac World.java
Note: World.java uses a deprecated API. Recompile with "-deprecation" for details
.
1 warning
C:\Java> javac -deprecation World.java
World.java:52: Note: The method java.awt.Dimension size() in class java.awt.Compon
ent has been deprecated.
Dimension d = size();

Note: World.java uses a deprecated API. Please consult the documentation for a be
tter alternative.

 

i) -sourcepath:

-sourcepath 소스패스

소스파일의 위치를 지정합니다.

 

j) -target:

-target 자바버젼

지정된 자바버젼의 VM에서 작동 되어지도록 클래스파일을 생성 시킵니다.

1.1
jvm 1.1 버젼에서 호환되어질수 있는 클래스 파일생성
1.2
jvm 1.2 버젼에서 호환되어질수 있는 클래스 파일생성
1.3
jvm 1.3 버젼에서 호환되어질수 있는 클래스 파일 생성

ex)

javac -target 1.2 Helloworld.java 

 

k) -bootclasspath 패스:

특정한 bootstrap또는 확장 클래스를 지정할수 있다.
기본적으로, 자바컴파일러는 javac(컴파일러명령)이 설치된 플래폼의 bootstrap과 확장클래스들을 통해서, 컴파일작업을 수행하지만,
bootclasspath 옵션을 사용하면, cross-compiling이라고 해서, 다른 자바플래폼의 bootstrap과 확장클래스들을 통해서, 컴파일 할수 있는 기능을 지원한다.
예를들어,
javac -target 1.1 -bootclasspath jdk1.1.7/lib/classes.zip -extdirs "" OldCode.java
컴파일러에게 현재 자신의 bootstrap을 사용하지 말고, jdk1.1.7/lib/classes.zip bootstrap클래스들을 사용해서 컴파일 하라고 
명령하는것이다.
참고로, 모바일자바에서, 모바일폰에 설정된, jvm에 맞도록, 소스코드를 컴파일하기 위해서, 주로 사용되어지는 옵션이다.

 

 

l) -extdirs 디렉터리:
특정한, 확장 디렉토리를 지정한다.cross-compiling시 주로, 사용되어지는 옵션이면, 각디렉터리들은 콜론(:)에 의해서, 분리되어진다.
컴파일시, 기술한 디렉터리의 클래스 파일을 참조한다.

 

========================================================

출처 : http://blog.naver.com/darkhan1?Redirect=Log&logNo=10009423507

 

java 컴파일시 알아 두면 유용하게 쓰일거 같다..

 

 

 

###################################################################

###################################################################

 

 

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
  
  
  
  
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client   to select the "client" VM
    -server   to select the "server" VM
    -hotspot   is a synonym for the "client" VM  [deprecated]
                  The default VM is client.
                  
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives, and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
 

 

M) package 선언된 Java class 실행시키기

- package위치는 CLASSPATH 하위 폴더부터로 인식한다. 따라서 Package폴더의 Root가 ClassPath에 지정되든지

.(현위치)를 ClassPath에 등록 후 현 위치 아래서부터 package의 위치를 지정한다.

java package.class명 (현위치 아래에 package폴더가 존재)

java com.test.SampleMain

 

:
Posted by 라면스프