[Java] Reverse iteration

Java 2016. 4. 29. 10:02

Java의 List 를 iteration 할때 역순으로 탐색하고 싶은경우 ListIterator 를 다음과 같이 사용하면 된다.

for (ListIterator iterator = list.listIterator(list.size()); iterator.hasPrevious();) {
  final Object listElement = iterator.previous();
}

'Java' 카테고리의 다른 글

[Java] Maven 빌드시 특정 excution 을 skip 하는 법  (0) 2021.01.20
[Java] Dependency Management  (0) 2020.10.08
[Java] JVM의 Thread Dump 확인하기  (0) 2015.12.28
[Java] Java 플랫폼 종류 요약  (0) 2014.10.15
[JSP] Scriptlet  (0) 2014.08.26
Posted by leechwin
,

Eclipse로 Java 프로젝트를 Run/Debug 시에 실행중 PermGen Space 에러가 나는경우가 있다.

이때는 VM 설정을 다음과 같이 수정한다.


  • Preferences > Java > Installed JREs > JRE 선택 > Edit > Default VM Arguments에 다음과 같이 입력 후 Finish
    • -XX:MaxPermSize=512m


Posted by leechwin
,

Eclipse를 실행시에 Java가 설치되어있는데도 다음과 같은 에러가 발생하는 경우가 있다.



이때에는 Eclipse 실행파일과 같은 경로에 위치하고 있는 eclipse.ini 파일을 열어서 다음 부분을 수정한다.

  • -xmx1024m 를 -xmx512m 으로 수정

이후 Eclipse가 실행이 된다.


Reference: http://stackoverflow.com/questions/7302604/eclipse-error-failed-to-create-the-java-virtual-machine


Posted by leechwin
,

Windows 에서 node 관련 npm 명령등을 수행시에 다음과 같이 'node-gyp' 관련 에러가 발생 하는 경우가 있다.

  • npm ERR! time@0.11.4 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the time@0.11.4 install script 'node-gyp rebuild'. npm ERR! This is most likely a problem with the time package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls time npm ERR! There is likely additional logging output above.


이것은 python 관련 환경 문제로 python 2.7과 Microsoft Visual Studio C++ 2012 Express를 설치해야한다.

설치 완료 후 다시 npm 명령을 수행하면 잘 실행이 된다.


Reference


Posted by leechwin
,

Eclipse 에서 Java Code Convention 을 설정 후 해당 룰에 해당하는 xml 파일로 대 Java 파일들을 포멧팅하는 방법에 대해 알아보자.


대량의 파일을 포멧팅할때 Eclipse Command-line 옵션과 변환된 룰파일을 사용하여 포멧팅 가능하다.


Eclipse code format from command line

Eclipse를 이용하여 command line 상태에서 java code formtting을 수행하는 방법을 알아보자.


다음과 같이 Eclipse Runtime Options을 이용하여 Java Code Formatter를 command line에서 수행 가능하다.

  • eclipse -application <id> (Runtime) // id는 eclipse product id를 의미

Eclipse내에 내장된 Java Code Formatter의 product id는 다음과 같다.

  • org.eclipse.jdt.core.JavaCodeFormatter

Eclipse Runtime Options을 이용하여 JavaCodeFormatter를 실행하는 예제 및 옵션은 다음과 같다.

Usage: eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter [ OPTIONS ] -config <configFile> <files>

   <files> Java source files and/or directories to format.

           Only files ending with .java will be formatted in the given directory.

   -config <configFile> Use the formatting style from the specified properties file.

                        Refer to the help documentation to find out how to generate this file.

OPTIONS:

 -help Display this message.

 -quiet Only print error messages.

 -verbose Be verbose about the formatting job.


JavaCodeFormatter의 Command line에서 쓰이는 config 파일형식은 Eclipse Coding Convention 설정에서 정의된 xml 파일 형식이 아니다.
따라서 xml 파일을 config 파일로 바꾸는 일이 필요하다.

xml 파일을 config 파일로 변환하기 위해 다음과 같이 수행한다.

  • Eclipse에서 아무 Java 프로젝트를 생성
  • Project 선택 후 우클릭 > Properties 메뉴 선택
  • Java Code Style > Formatter > Enable project specific settings 선택 > Active profile에서 TIDE_JAVA_CONVENTION.xml 을 import 하거나 메뉴이 이미 있다면 선택
  • Apply > OK
  • 생성한 Java 프로젝트 경로로 이동
  • 프로젝트 경로 하위에 .settings 폴더밑의 org.eclipse.jdt.core.prefs 파일이 config 파일이므로 이를 원하는 곳에 복사해놓는다.

ConfigFile을 생성했으면 다음과 같이 실행 가능하다.

$ {eclipse path}/eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config {configFile path} {source file path}


// example

$ /home/leechwin/eclipse/eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config /home/leechwin/eclipse/org.eclipse.jdt.core.prefs /home/leechwin/git/org.leechwin.com/src/


References


Posted by leechwin
,

Eclipse 에서 Java Code Convention 을 설정 하는 법에 대해 알아보자.

Eclipse Preference 에서 Java Code Formate 에 대한 여러가지 설정이 가능하다.


Eclipse Java Formatter

Eclipse에서 Ctrl + Shift + F 를 누르면 해당 파일에 코딩 컨벤션 룰이 적용되게 하는 방법

  1. 컨벤션룰 파일을 다운로드
    1. JAVA_CONVENTION.xml

  2. Eclipse에서 다음 설정으로 이동
    1. Preference > Java > Code Style > Formatter
  3. Formatter 설정
    1. Import 버튼 클릭 > 다운받은 컨벤션룰 파일을 선택 > Apply > OK




Eclipse Java Save Actions

Eclipse에서 코드 수정 후 저장시 자동으로 코딩 컨벤션 룰이 적용되게 하는 방법

  1. Eclipse Java Formatter 적용작업이 선행되어있어야 한다.
  2. Eclipse에서 다음 설정으로 이동
    1. Preference > Java > Editor > Save Actions
  3. Save Actions 설정
    1. Perform the selected actions on save 체크
    2. Format source code 체크
      1. Format all lines
        1. 저장시 수정된 파일 전체라인에 대해서 코딩 컨벤션을 적용
      2. Format edited lines
        1. 저장시 수정된 부분에 대해서 코딩 컨벤션을 적용
    3. Organize imports 체크
  4. Apply > OK



Posted by leechwin
,

Proxy 를 쓰고있는 환경에서 Eclipse Update Site 와 Eclipse Marketplace 등에 접속이 안되는 경우 다음과 같이 설정을 한다.


  • Preferences > Network Connections
    • Active Provider 를 Manual 로 설정
    • HTTP/HTTPS Proxy 설정
    • SOCKS 에 대한 설정은 하지 않는다.
  • 이후 Eclipse 를 재시작하면 된다.


Posted by leechwin
,

Jenkins 의 버전을 업데이트 하고 싶을때 수동으로 war 파일만 다운받아 교체하고 싶은경우 다음과 같이 진행한다.

  • 구동중인 Jenkins 중지
    • $ service jenkins stop

  • war 파일을 다운받아 다음 경로에 복사
    • $ sudo mv jenkins.war /usr/share/jenkins

  • Jenkins 재가동
    • $ service jenkins start

이후 업데이트된 버전의 Jenkins 가 반영되어 가동된다.

Posted by leechwin
,

Ubuntu 에서 SSD 카드 사용하려고 할때 가끔 Unable to mount.. 로 시작하는 에러가 발생하면서 SD 카드를 인식 못하는 경우가 있다.

원인은 SSD카드가 Windows 환경에서 포멧되어 사용중인 파일시스템을 리눅스에서 인지를 못하는 문제이다.

이 문제를 해결하려면 리눅스에 해당 파일 시스템을 인식 할 수 있는 모듈을 다음과 같이 설치하면 해결이 된다.

  • sudo apt-get install exfat-fuse

위의 모듈이 성공적으로 설치되면 SD 카드가 정상적으로 인식된다.

Reference: http://askubuntu.com/questions/664765/unable-to-mount-128gb-micro-sdxc-storage-card



Posted by leechwin
,

Jenkins Plugin 개발시에 빌드 패키징을 위한 maven 설치 방법


Ubuntu

  • Java가 설치되어 있고 JAVA_HOME 환경변수 설정이 되어 있어야 한다.
    •  export JAVA_HOME=/path/your/jdk
       export PATH=$JAVA_HOME/bin:$PATH

  • apt-get 을 통하여 설치
    • sudo apt-get install maven2
  • ~/.m2/settings.xml 파일을 수정하거나 없다면 새로생성 (윈도우는 %USERPROFILE%\.m2\settings.xml)
    • <settings>

        <pluginGroups>

          <pluginGroup>org.jenkins-ci.tools</pluginGroup>

        </pluginGroups>


        <profiles>

          <!-- Give access to Jenkins plugins -->

          <profile>

            <id>jenkins</id>

            <activation>

              <activeByDefault>true</activeByDefault> <!-- change this to false, if you don't like to have it on per default -->

            </activation>

            <repositories>

              <repository>

                <id>repo.jenkins-ci.org</id>

                <url>http://repo.jenkins-ci.org/public/</url>

              </repository>

            </repositories>

            <pluginRepositories>

              <pluginRepository>

                <id>repo.jenkins-ci.org</id>

                <url>http://repo.jenkins-ci.org/public/</url>

              </pluginRepository>

            </pluginRepositories>

          </profile>

        </profiles>

        <mirrors>

          <mirror>

            <id>repo.jenkins-ci.org</id>

            <url>http://repo.jenkins-ci.org/public/</url>

            <mirrorOf>m.g.o-public</mirrorOf>

          </mirror>

        </mirrors>

        <!-- 프록시 설정 -->

        <proxies>

          <proxy>

            <id>optional2</id>

            <active>true</active>

            <protocol>https</protocol>

            <host>[Proxy URL]</host>

            <port>[Port]</port> 

          </proxy>

        </proxies>

      </settings> 

  • 다음 명령을 통하여 필요한 패키지를 설치
    • $ mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create
  • Jenkins Plugin 개발 경로에서 패키징 실행
    • $ mvn package


Reference: https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial

Posted by leechwin
,