2013-10-30 2 views
0

이것은 실행 가능한 jar 파일을 생성하는 데 정확히 수행 된 단계이므로 두 번 클릭하여 내 스윙 프로그램을 실행할 수 있지만 "유효하지 않거나 손상된 jar 파일"이라는 오류 메시지가 나타납니다. 명령 프롬프트를 통해 실행 내게 같은 오류가 발생실행 가능한 jar 파일을 열 수 없습니다.

Step 1:create a .java file which contains my swing code 
Step 2:compile the .java file to .class file 
Step 3:create jar file using the command jar cf name.jar classname.class 
Step 4:open jar file using winrar archiever and modify manifest file by adding Main-class:classname 
Step 5:try to execute the jar file 

위의 단계는 작동하지 않으며 나는 이유를 이해하지 못합니까?

java -cp name.jar Classname 

을 명령 프롬프트에서 오류를 검사 :

나는 당신이 시도 할 수도

Step 1:create a .java file which contains my swing code 
Step 2:compile the .java file to .class file 
Step 3:create jar file using the command jar cf name classname.class 
Step 4:open jar file using winrar archiever and modify manifest file by adding Main-class:classname 
Step 5:try to execute the jar file.In this case i can open my file through command prompt but not by double clicking. I tried to select javaw option through Open with option but it doesn't give any ouput(not even error) 
+0

'java -jar file.jar '로 실행 해보십시오. –

+0

나는 그것을 시도했지만 동일한 오류 "잘못된 또는 손상된 병 파일"을 제공합니다 – Bhushan

답변

2

다른 일을 시도했다.

프로그램에 외부 라이브러리가 필요한 경우 매니페스트 파일에서 언급 할 수 있습니다. lib이 jar 파일은 같은 디렉토리에

Class-Path: lib/file1.jar lib/file2.jar 

.

+0

이것은 작동합니다. 하지만 왜 설명 할 수 있니? – Bhushan

+0

'-cp'는 클래스 경로에 jar를 포함시키는 것을 의미합니다. –

+0

미안하지만 그것이 의미하는 바를 이해하지 못했습니다. 다시 설명해 주시겠습니까? – Bhushan

관련 문제