⑨ 직무역량강화/기타 | Posted by 서풍의신 재령 2012/02/15 14:30

[JAVA] javac options

- 출처 :  http://letmelove.net/blog/entry/javac-%EC%98%B5%EC%85%98%EA%B3%BC-java%EC%98%B5%EC%85%98 

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

** 유닉스에서 클래스 경로(classpath) 항목은 콜론(:) 으로 구분한다.
** 윈도우에서 클래스 경로(classpath) 항목은 세미콜론(;) 으로 구분한다.
 

b) -d
 
 
-d directory
 
클래스 파일을 생성할 Root 디렉토리를 지정한다.

기본적으로 컴파일러는 -d 옵션을 주지 않으면 소스파일이 위치한 디렉토리에 클래스 파일을 생성시킨다.
 
예를 들어 Hello.java파일이 C:\Java 디렉토리에 존재하고 클래스 파일의 Root 디렉토리를 C:\Java\Classfiles 라고 하면 

javac -d C:\Java\Classfiles C:\Java\Hello.java

이다.

만약 -d 옵션을 사용하려고 하는데 Root 디렉토리(위예에서는 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의 위치를 출력한다.

eg)
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 이라고 해서 다른 JAVA 플랫폼의 bootstrap과 확장 클래스들을 통해서 compile 할 수 있는 기능을 지원한다.
 
예를들어

javac -target 1.1 -bootclasspath jdk1.1.7/lib/classes.zip -extdirs "" OldCode.java

컴파일러에게 현재 자신의 bootstrap을 사용하지 말고 jdk1.1.7/lib/classes.zip bootstrap 클래스들을 사용해서 컴파일 하라고 
명령하는것이다.
 
참고로 mobile JAVA에서 모바일폰에 설정 된 jvm에 맞도록 소스코드를 컴파일하기 위해서 주로 사용되어지는 옵션이다.

l) -extdirs 디렉토리

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


M) package 선언된 Java class 실행

java package.class명 (현 위치 아래에 package폴더가 존재)
 
package 위치는 CLASSPATH 하위 폴더부터로 인식한다. 따라서 Package 폴더의 Root가 ClassPath에 지정되든지 .(현 위치)를 ClassPath에 등록 후 현 위치 아래서부터 package의 위치를 지정한다.

java com.test.SampleMain

###################################################################
javac options
###################################################################

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
 
크리에이티브 커먼즈 라이선스
Creative Commons License

'⑨ 직무역량강화 > 기타' 카테고리의 다른 글

[JAVA] javac options  (0) 2012/02/15
[보안] CC(Common Criteria)  (0) 2012/01/12
[보안] httpOnly Cookie  (0) 2012/01/11
[MS-DOS] MS-DOS창에서 코드 페이지 변경하는 방법  (0) 2011/11/04
[성능] MIPS  (0) 2010/02/12
[TP Monitor] CICS Transaction Server 1.3  (0) 2008/11/10
⑨ 직무역량강화/Design Patterns | Posted by 서풍의신 재령 2012/01/18 23:00

[Design Pattern] Observer Pattern


옵저버 패턴 (Observer Pattern)

Type - Behavioral

한 객체(Subject)의 상태가 바뀌면 그 객체에 의존하는 다른 객체(Observer)들 에게 연락이 가고 자동으로 내용이 갱신되는 1:n (one-to-many) 의존성을 정의함


적용 예시 )

1. Observer Pattern 적용



2. JDK 내장 Observable Class, Observer Interface 사용


- Java 구현 Src

크리에이티브 커먼즈 라이선스
Creative Commons License

'⑨ 직무역량강화 > Design Patterns' 카테고리의 다른 글

[Design Pattern] Observer Pattern  (0) 2012/01/18
[Design Pattern] Strategy Pattern  (0) 2012/01/18
⑨ 직무역량강화/Design Patterns | Posted by 서풍의신 재령 2012/01/18 22:06

[Design Pattern] Strategy Pattern



스트래티지 패턴 (Strategy Pattern)

Type - Behavioral

동일 계열의 알고리즘군을 정의하고 각각의 알고리즘을 캡슐화하여 이들을 상호 교환해서 사용할 수 있도록 만든다. 스트래티지를 활용하면 알고리즘을 사용하는 클라이언트와는 상관없이 독립적으로 알고리즘을 다양하게 변경할 수 있다.

적용 예 )

- 패턴 적용


- Java 구현 Src
 

 
크리에이티브 커먼즈 라이선스
Creative Commons License

'⑨ 직무역량강화 > Design Patterns' 카테고리의 다른 글

[Design Pattern] Observer Pattern  (0) 2012/01/18
[Design Pattern] Strategy Pattern  (0) 2012/01/18
⑨ 직무역량강화/Transaction | Posted by 서풍의신 재령 2012/01/06 10:57

[Transaction] JAVA Transaction Programing




크리에이티브 커먼즈 라이선스
Creative Commons License

'⑨ 직무역량강화 > Transaction' 카테고리의 다른 글

[Transaction] XA vs non XA  (0) 2012/01/06
[Transaction] JAVA Transaction Programing  (0) 2012/01/06
⑨ 직무역량강화/Spring FW | Posted by 서풍의신 재령 2011/07/06 14:17

[Spring] Dependency Injection

출처 : Anyframe 3.2.0 Manual ( http://dev.anyframejava.org/anyframe/doc/core/3.2.0/corefw/guide/annotation-dependencies.html )

특정 Bean의 기능 수행을 위해 다른 Bean을 참조해야 하는 경우 사용하는 Annotation으로는 @Autowired 또는 @Resource가 있다.
  • @Autowired

  • Spring Framework에서 지원하는 Dependency 정의 용도의 Annotation으로, Spring Framework에 종속적이긴 하지만 정밀한 Dependency Injection이 필요한 경우에 유용하다.
  • @Resource

  • JSR-250 표준 Annotation으로 Spring Framework 2.5.* 부터 지원 가능한 Annotation이다. Annotation 사용으로 인해 특정 Framework에 종속적인 어플리케이션을 구성하지 않기 위해서는 @Resource를 사용할 것을 권장한다. @Resource를 사용하기 위해서는 클래스패스 내에 jsr250-api.jar 파일이 추가되어야 함에 유의해야 한다.
다음은 @Resource를 사용한 예이다.
@Service
public UserServiceImpl implements UserService {
    @Resource
    private UserDAO userDAO;
}

@Autowired와 @Resource를 사용할 수 있는 위치는 다음과 같이 약간의 차이가 있으므로 필요에 따라 적절히 사용하면 된다.
  • @Autowired : 필드, 생성자, 입력파라미터가 여러개인 메소드(@Qualifier는 메소드의 파라미터)에 적용 가능
  • @Resource : 필드, 입력 파라미터가 한 개인 빈 프로퍼티 setter 메소드에 적용가능
@Autowired나 @Resource를 필드에 직접 정의하는 경우 별도 setter 메소드는 정의하지 않아도 된다.

Type-driven Injection

@Autowired는 기본적으로 type-driven injection 이다. 타입으로 참조할 빈을 찾았을 때 같은 타입의 빈이 여러 개 검색되었을 경우, @Qualifier annotation을 사용하여 구분할 수 있도록 해준다. 

다음은 @Qualifier를 사용한 예이다.
@Service
public ProductService {
    @Autowired
    @Qualifier("electronics")
    private ProductCategory productCategory;
}
Qualifier를 정의하는 방법에는 다음과 같이 두가지가 있다.
  • XML을 사용한 정의
  • <bean class="anyframe.sample.springmvc.annotation.web.SimpleProductCategory">
        <qualifier value="electronics"/>
        <!-- inject any dependencies required by this bean -->
    </bean>
    
    <bean class="anyframe.sample.springmvc.annotation.web.SimpleProductCategory">
        <qualifier value="cosmetics"/>
        <!-- inject any dependencies required by this bean -->
    </bean>
    		
  • Annotation을 사용한 정의
  • @Component
    @Qualifier("electronics")
    public class ElectronicsProductCategory implements ProductCategory {
    	//...
    }

기본적으로 @Autowired가 적용된 프로퍼티는 필수이기 때문에 반드시 해당 빈이 존재해야 하지만, required 속성을 false로 설정하는 경우에는 해당되는 Bean을 찾지 못하더라도 에러가 발생하지 않는다.
@Service
public UserService implements UserService {
    @Autowired(required=false)
    private UserDAO userDAO;
}

Naming Auto Wired Dependencies

@Resource annotation은 다음과 같은 경우에 사용한다.
  • Bean name으로 Dependency Injection을 하고자 하는 경우
  • Type-driven injection을 할 수 없는 Collection이나 Map 타입의 빈
@Resource를 사용하는 경우 참조되는 Bean은 변수명을 Bean Name으로 하여 Spring 컨테이너에 의해 자동으로 인지되는데, 변수명을 이용하여 참조 관계에 놓인 Bean을 찾았는데 해당 Bean이 없는 경우에는 클래스 타입을 이용하게 된다. 참조 관계에 놓인 Bean의 Name을 직접 명시하고자 하는 경우에는 다음과 같이 'name' 속성을 부여할 수 있다.
@Service
public UserServiceImpl implements UserService {
    @Resource (name="uDAO")
    private UserDAO userDAO;
}

Custom Qualifier

@Autowired annotation을 이용하여 보다 정밀하게 Dependency Injection을 수행할 필요가 있을 경우, Spring Framework의 Custom Qualifier를 사용할 수 있다.
1.Custom Qualifier 정의
다음은 @UserDAOQualifier라는 Custom Qualifier 코드의 일부로 @UserDAOQualifier는 dbtype이라는 속성 정보를 갖고 있다. dbtype 따라 참조해야 할 Bean이 달라지는 경우 즉, DBMS 유형에 따라 다른 데이터 접근 로직이 실행되어야 하는 경우에 사용될 수 있다.
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention (RetentionPolicy.RUNTIME)
@Qualifier
public @interface UserDAOQualifier {
    String dbtype();
}
java.lang.annotation.Target은 사용한 Annotation이 어디에 적용될 것인지 Annotation을 선언할 때 정의한다. (예를 들면 클래스나 메소드, 필드 등.) 만약 Target이 정해지지 않으면 어디에서나 사용가능한 Annotation이 된다. java.lang.annotation.Retention은 Annotation을 선언할때 쓰이는데, 다음과 같은 Parameter들이 사용 가능하다.
  • RetentionPolicy.SOURCE : 해당 Annotation이 소스레벨이라는 사실을 알려줌 (default)
  • RetentionPolicy.CLASS : 소스코드와 컴파일된 클래스 파일에는 사용 가능하지만, 런타임에는 사용 불가.
  • RetentionPolicy.RUNTIME : 소스코드, 컴파일된 코드, 런타임에도 사용 가능

2.XML 정의
속성 정의 XML 파일 내에 Custom Qualifer로써 UserDAOQualifier 클래스에 대해 정의하여 특정 클래스에서 해당 Annotation을 사용할 수 있도록 한다.
<bean id="customAutowireConfigurer"
    class="org.springframework.beans.factory.annotation.CustomAutowireConfigurer">
    <property name="customQualifierTypes">
        <set><value>…UserDAOQualifier</value></set>
    </property>
</bean>
다음은 dbtype에 따라 어떤 Bean이 할당될 것인지를 명시하는 부분으로 dbtype이 Oracle일 경우 UserDAOWIthOracle의 인스턴스가 컨테이너에 의해 인지되도록 정의되어 있음을 알 수 있다.
<bean class="...UserDAOWIthOracle">
    <meta key="dbtype" value="oracle"/>
</bean>

3.활용
앞서 정의한 Custom Qualifier @UserDAOQualifier는 다음과 같이 사용한다. 다음의 코드에서 dbtype을 oracle로 정의하고 있으므로, xml 정의에 따라 userDAO라는 변수에는 UserDAOWIthOracle의 인스턴스가 할당될 것이다.
public class UserServiceImpl implements UserService {
    @Autowired
    @UserDAOQualifier(dbtype="oracle")
    private UserDAO userDAO;
    // ...
}
크리에이티브 커먼즈 라이선스
Creative Commons License

'⑨ 직무역량강화 > Spring FW' 카테고리의 다른 글

[Spring] Dependency Injection  (0) 2011/07/06
<PREV 1 2 3 4 5 ... 7 NEXT>