2014-02-27 2 views
3

미리 사과 - 많은, 많은, 많은 아주 많은 비슷한 질문이 있다는 것을 알고 있지만 내 상황에 특정한 것을 묻고 싶었습니다.NoClassDefFoundError 명령 줄에서 실행하려고 시도 할 때

동일한 디렉토리에 여러 개의 Java 및 jar 파일이 있습니다. 나는 잘 컴파일 할 수 있었고 결국 같은 디렉토리에 여러 개의 클래스 파일을 만들게되었다. 그러나 나는 그것이 지정된 클래스를 찾을 수 없다는 그것이 않는 NoClassDefFoundError를 제공하는 프로그램을 실행 갈 때 :

C:\Users\DB\Desktop\nextreports-integration-demo\src\ro\nextreports\integration> 
java -cp ".;*.jar" SimpleDemo 
Exception in thread "main" java.lang.NoClassDefFoundError: SimpleDemo (wrong nam 
e: ro/nextreports/integration/SimpleDemo) 

내가 더 높은 수준의 디렉토리에서 같은 일을 시도했지만 그것은 차이하지 :

C:\Users\DB\Desktop\nextreports-integration-demo\src>java -cp ".\ro\nextreports\ 
integration\*.jar;.\ro\nextreports\integration" SimpleDemo 
Exception in thread "main" java.lang.NoClassDefFoundError: SimpleDemo (wrong nam 
e: ro/nextreports/integration/SimpleDemo) 

소스 파일의 패키지 문이다 : 나는 매우 초등학교 무언가를 내려다 해요 느낌이

package ro.nextreports.integration; 

. 미리 감사드립니다.

편집 : 대단히 감사합니다.

java -cp ".\ro\nextreports\integration\nextreports-engine-6.3.jar;.\ro\nextreports\integration\commons-jexl-2.1.1.jar;.\ro\nextreports\integration\commons-logging-1.1.1.jar;.\ro\nextreports\integration\derby-10.10.1.1.jar;.\ro\nextreports\integration\itext-2.1.7.jar;.\ro\nextreports\integration\itext-rtf-2.1.7.jar;.\ro\nextreports\integration\itextpdf-5.0.6.jar;.\ro\nextreports\integration\jcalendar-1.3.2.jar;.\ro\nextreports\integration\jcommon-1.0.15.jar;.\ro\nextreports\integration\jfreechart-1.0.12.jar;.\ro\nextreports\integration\jofc2-1.0.1.jar;.\ro\nextreports\integration\mysql-connector-java-5.1.23-bin.jar;.\ro\nextreports\integration\mysql-connector-java-5.1.23-bin.jar;.\ro\nextreports\integration\poi-3.7.jar;.\ro\nextreports\integration\winstone-lite-0.9.10.jar;.\ro\nextreports\integration\xstream-1.3.1.jar;" ro.nextreports.integration.SimpleDemo 

그런데 왜 나는 * .jar 파일에 대한 와일드 카드를 사용할 수 없습니다 : 그것은 다음과 같이 작동? 예를 들어, 어떤 jar 파일의 클래스에 대한 않는 NoClassDefFoundError에 다음 리드는 내가 명시 적으로하지 않습니다

java -cp ".;.\ro\nextreports\integration\*.jar" ro.nextreports.integration. 
SimpleDemo 
+1

클래스의 정규화 된 이름을 사용해야합니다. 패키지 포함. –

+0

경로 설정 및 classpath 변수가 환경 변수 설정에 설정되어 있는지 확인하십시오. – Sambhav

답변

1

이이 디렉토리 트리입니다 가정 : 패키지 선언에서

src/ 
    ro/ 
    nextreports/ 
     integration/ 
     SimpleDemo.class 

, 당신의 컴파일 된 클래스는 서브 디렉토리 integration에 있어야합니다. 해당 디렉토리에 실제로 SimpleDemo.class이 있는지 확인하십시오. 이것이 맞다면, classpath는 src 디렉토리의 내용을 포함한다. 당신이 어떤 JAR 종속성을 가지고 있지 않은 경우,이 같은 src 디렉토리에서 응용 프로그램을 실행할 수 있다는 것을 의미

는 :

java -cp . ro.nextreports.integration.SimpleDemo 

당신은 정규화 된 클래스 이름을 사용해야합니다.

jar 파일을 가지고 있으므로 클래스 패스에도 jar 파일을 포함해야합니다. 현재 디렉토리에 one SRC 위의 디렉토리에있는 JAR 및 another을 가정 해, 당신은 사용할 수 있습니다 : 다른 디렉토리에서 실행할 경우

java -cp ../one.jar;another.jar;. ro.nextreports.integration.SimpleDemo 

, 그것은 여전히 ​​작동을하면 클래스 경로의 상대적 디렉토리 또는 사용을 검토하는 경우 클래스 경로를 설명하는 절대 디렉토리. 확실하지는 않지만 일반적으로 현재 디렉토리는 Java 실행 파일에 의해 클래스 경로에 항상 포함됩니다.

관련 문제