클래스 경로의 여러 항아리에 동일한 클래스가 존재하는지 발견 할 도구가 있습니까?

StackOverflow https://stackoverflow.com/questions/135971

  •  02-07-2019
  •  | 
  •  

문제

클래스 경로에 동일한 클래스의 다른 버전이 포함 된 두 개의 항아리가있는 경우 클래스 경로 순서가 중요 해집니다.

주어진 클래스 경로 또는 폴더 세트에서 그러한 잠재적 충돌을 감지하고 플래그 할 수있는 도구를 찾고 있습니다.

확실히 시작하는 스크립트 :

classes=`mktemp`
for i in `find . -name "*.jar"`
do
    echo "File: $i" > $classes
    jar tf $i > $classes
    ...
done

나중에 영리한 정렬/uniq/diff/grep/awk가 잠재력을 가지고 있지만, 누군가가 기존 솔루션을 알고 있는지 궁금합니다.

도움이 되었습니까?

해결책

그만큼 자동 표시기 JBoss의 도구는 또 다른 후보입니다. "클래스/패키지가 여러 JAR 파일에있는 경우 스팟"

다른 팁

보입니다 jarfish "Dupes"명령으로 원하는 것을 할 것입니다.

나는 당신 자신을위한 도구를 쓰는 것이 너무 어렵지 않을 것이라고 생각합니다.

system.getProperty ( "java.class.path")로 클래스 경로 항목을 얻을 수 있습니다.

그런 다음 그곳에 나열된 항아리, ZIP 또는 디렉토리를 걸어 가서 수업에 대한 모든 정보를 수집하고 문제를 일으킬 수있는 정보를 찾으십시오.

이 작업은 최대 1-2 일이 걸립니다. 그런 다음이 클래스를 응용 프로그램에 직접로드하고 보고서를 생성 할 수 있습니다.

아마도 java.class.path 속성은 복잡한 커스텀 클래스로드가있는 일부 인프라에서 실행되면 모든 클래스를 보여줄 것입니다 (예 : LDAP에서 클래스를로드하는 앱을 한 번 보았습니다).

그녀는 당신이 유용 할 수있는 도구입니다. 나는 그것을 내 자신을 사용하지는 않지만 시도해보고 결과를 알려줍니다.

http://www.jgoodies.com/freeware/jpathreport/features.html

자신만의 도구를 만들려면 이전에 게시 된 동일한 쉘 스크립트에 사용하는 코드가 있지만 Windows 시스템에서 사용하는 코드가 있습니다. JAR 파일의 톤이있을 때 더 빨리 실행됩니다.

디렉토리를 재귀 적으로 걸어가고 클래스 경로를 읽고 .class 시간 속성을 비교하는 대신 사용하여 수정할 수 있습니다.

필요한 경우 서브 클래스 할 수있는 명령 클래스가 있습니다. "찾기"의 execute 옵션에서 생각하고있었습니다.

이것은 내 자신의 코드이므로 작업을 수행하기 위해 "생산 준비"가 아니 었습니다.

import java.io.*;
import java.util.zip.*;


public class ListZipContent{
    public static void main( String [] args ) throws IOException {
        System.out.println( "start " + new java.util.Date() );
        String pattern = args.length == 1 ? args[0] : "OracleDriver.class";// Guess which class I was looking for :) 
        File file = new File(".");
        FileFilter fileFilter = new FileFilter(){
            public boolean accept( File file ){
                return file.isDirectory() || file.getName().endsWith( "jar" );
            }
        };
        Command command = new Command( pattern );
        executeRecursively( command, file, fileFilter );
        System.out.println( "finish  " + new java.util.Date() );
    }
    private static void executeRecursively( Command command, File dir , FileFilter filter ) throws IOException {
        if( !dir.isDirectory() ){
            System.out.println( "not a directory " + dir );
            return;
        }
        for( File file : dir.listFiles( filter ) ){
            if( file.isDirectory()){
                executeRecursively( command,file , filter );
            }else{
                command.executeOn( file );
            }
        }
    }
}
class Command {

    private String pattern;
    public Command( String pattern ){
        this.pattern = pattern;
    }

    public void executeOn( File file ) throws IOException {
        if( pattern == null ) { 
            System.out.println( "Pattern is null ");
            return;
        }

        String fileName = file.getName();
        boolean jarNameAlreadyPrinted = false;

        ZipInputStream zis = null;
        try{
            zis = new ZipInputStream( new FileInputStream( file ) );

            ZipEntry ze;
            while(( ze = zis.getNextEntry() ) != null ) {
                if( ze.getName().endsWith( pattern )){
                    if( !jarNameAlreadyPrinted ){
                        System.out.println("Contents of: " + file.getCanonicalPath()  );
                        jarNameAlreadyPrinted = true;
                    }
                    System.out.println( "    " + ze.getName() );
                }
                zis.closeEntry();
            }
        }finally{
            if( zis != null ) try {
                zis.close();
            }catch( Throwable t ){}
        }
    }
}

이게 도움이 되길 바란다.

ClassPath 도우미 약간 도움이되는 일식 플러그인입니다.

jwhich 또는 jcfind를 사용해보십시오

http://javaclassfind.wiki.sourceforge.net/

http://which4j.dev.java.net/

내용 다운로드 및 설치를 싫어하는 경우이 One Line 명령을 사용하여 Jar가 표준 GNU 도구와 충돌 할 수 있습니다. 초보적이지만 원하는대로 확장 할 수 있습니다.

ls *.jar | xargs -n1 -iFILE unzip -l FILE | grep class | sed "s,.* ,," | tr "/" "." | sort | uniq -d | xargs -n1 -iCLASS grep -l CLASS *.jar | sort -u

(항아리가 많으면 달리기가 약간 느립니다)

설명 : 모든 항아리에 모든 파일을 나열하고, 클래스 파일을위한 그레프, 속임수를 찾은 다음, 원래 항아리를 잡아서 어디에 나타나는지 확인합니다. 더 복잡한 스크립트로 더 효율적으로 만들 수 있습니다.

jarclassfinder 또 다른 일식 플러그인 옵션입니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top