jar 사용에 관하여

mr.lee의 이미지

jar 로 압축할때 와일드카드를 써서 파일 필터링을 할 수 있는지요? 별 생각없이 죽 써왔는데 문득 그게 필요한데 해보니 안되는것 같아서 말이죠.
이를테면,
디렉토리 구조가 workspace/src/com/company/util/ 이렇게 되어 있고 util아래에 *.java 파일들과 .class 파일등등이 있다 쳤을때 말이죠.
cd workspace 해서 com부터 *.class 파일만 묶을려고 한다고 했을때

jar cvf test.jar -C src/ . 이렇게 하면 com아래 모든 파일이 다 묶이는거고.
jar cvf test.jar -C src/ * 이렇게 하면 에러나고..
jar cvf test.jar -C src/ *.class 이것도 마찬가지 에러.

또한,

cd src
jar cvf test.jar . 이렇게 하면 위 첫번째와 같고,
jar cvf test.jar * 이건 이번엔 에러안나고 위와 동일한 결과고
jar cvf test.jar *.class 이것은 역시 마찬가지로 에러
jar cvf.test.jar .class 뭐 이것도 역시나 에러.
find com/ -name '*.class' | jar cvf test.jar 뭐 이것도 안되는군요.

물론, 쉘스크립트에서 find를 이용해서 리스트를 만들고 그 값으로 jar를 수행시키면 되겠지만..
jar에서 바로 하는 방법은 원래 없었나보죠?

lovian의 이미지

좀 다른 방향입니다만,

아주 빌드를 다른 디렉토리에 하시는건 어떤가요?

빌드시에 -d 옵션으로 classes 등의 디렉토리에 하는걸 봐서요.

-----------------
한글을 사랑합니다.

-----------------
한글을 사랑합니다.

mr.lee의 이미지

아네..위피 개발을 리눅스에서 하다보니 필요성이 생겨서요. 원래 안되는거던가 궁금하기도 하구요.

mr.lee의 이미지

음.. 제가 쉘스크립트를 만들어 봤습니다. 아마 유용하게들 사용하실 상황도 있으리라 생각합니다.

스크립트명은 kar.sh 이며 사용법은 그냥 kar.sh 만 (실행가능 속성 있는 상태에서) 입력하면 나오구요.
윈도우+cygwin 에서는 cygwin/bin 패스가 PATH에 잡혀 있는 상태에서 bash kar.sh 하시면 되겠네요.
윈도우 커맨드에도 find가 있기 때문에 find_cmd는 절대경로로 대입하셔서 사용하시면 좋겠죠. (PATH 우선순위 따라 안해도 될수도 있겠지만)

(사용예)
패키지명은 com.company.util 이 된다.
workspace/src/com/company/util/ 아래에 *.class 와 *.java 파일들이 있다고 했을때 혹은 .svn 의 여러 파일들이 있을수도 있겠다.
workspace/out/ 안에 class (혹은 java) 파일들만 묶은 jar를 만들어 넣고 싶을때

cd workspace
리눅스: $ kar.sh cvf out/test.jar src *.class
윈도우: bash kar.sh cvf out/test.jar src *.cass

이것은 원래 jar의 용법인 (에러는 나지만)

jar cvf out/test.jar -C src *.class

와 같은 형태의 구문이므로 사용하시기가 쉬울것입니다.

cvf[M], uvf[M] 등의 옵션을 사용할때 사용하시면 되겠으며..약간의 수정이 필요하겠지만 패턴은 find에서 사용할 수 있는 모든 옵션과 표현식을 이용할 수 있겠죠.

이를테면, -name 이나 -iname이 아닌 정규표현식으로 원하는 모든 리스트를 긁어오고 싶다면..

kar.sh 의 $find_cmd . -name 부분을 find a -regextype egrep -iregex 이렇게 바꾸고

$ kar.sh cvf out/test.jar src ".+\.(class|java)"

이렇게 하면 class와 java 파일들만 모을 수 있겠네요.

#!/bin/bash
 
function strcat()
{
    s1_val=${!1}
    s2_val=${!2}
    s3_val=${!3}
    eval "$1"=\'"${s1_val} -C ${s2_val} ${s3_val}"\'
}
 
if [ "$4" == "" ]
  then
    echo "Usage: kar jar_option jar_name dir_name pattern"
    echo ""
    echo "jar_option    cvf or uvf"
    echo "jar_name      jar name including path"
    echo "dir_name      change dir name like -C option"
    echo "pattern       pattern for file list"
    exit
  fi
 
jar_option=$1
jar_name=$2
dir_name=$3
pattern=$4
 
list=""
#find_cmd="c:/cygwin/bin/find"
find_cmd="/usr/bin/find"
 
cd $dir_name
 
for file in $($find_cmd . -name "$pattern")
  do
    strcat list dir_name file
  done
 
cd -
 
jar $jar_option $jar_name $list

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.