IT박스

JAR 파일에서 메인 클래스 매니페스트 속성을로드하지 못한 이유는 무엇입니까?

itboxs 2020. 9. 17. 07:25
반응형

JAR 파일에서 메인 클래스 매니페스트 속성을로드하지 못한 이유는 무엇입니까?


이런 식으로 JAR 파일을 만들었습니다 jar cf jar-file input-files. 이제 실행하려고합니다. 실행되지 않음 (jre 명령을 찾을 수 없음) :

jre -cp app.jar MainClass

이것은 작동하지 않습니다.

java -jar main.jar

(main.jar에서 Main-Class 매니페스트 속성을로드하지 못했습니다.)

나는 또한 발견했다

JAR 파일로 패키지 된 애플리케이션을 실행하려면 (버전 1.2-Main-Class 매니페스트 헤더 필요)

"Main-Class 매니페스트 헤더"는 무엇입니까? 어떻게 만들고 어디에 두나요?


나는 당신의 증상을 믿을 수 없습니다.

  • jre명령을 찾을 수없는 경우 실행 jre -cp app.jar하면 동일한 오류가 발생합니다.
  • 클래스 경로에 JAR 파일을 추가하는 것만으로도 오류가 발생하지 않습니다.

다음을 실행하면이 오류가 표시 될 것으로 예상합니다.

java -jar app.jar

Main-Class 헤더는 JAR 파일의 매니페스트에 있어야합니다. 이것은 다른 필수 라이브러리와 같은 항목에 대한 메타 데이터입니다. 적절한 매니페스트를 만드는 방법 Sun 설명서참조하십시오 . 기본적으로 다음과 같은 줄을 포함하는 텍스트 파일을 만들어야합니다.

Main-Class: MainClass

그런 다음 실행

jar cfm app.jar manifest.txt *.class

  1. 클래스 경로를 설정하고 컴파일

    javac -classpath "C : \ Program Files \ Java \ jdk1.6.0_ updateVersion \ tools.jar"yourApp.java

  2. manifest.txt 생성

    메인 클래스 : yourApp 개행

  3. yourApp.jar 생성

    jar cvf0m yourApp.jar manifest.txt yourApp.class

  4. yourApp.jar 실행

    java -jar yourApp.jar


다음으로 실행할 수 있습니다.

java -cp .;app.jar package.MainClass

JAR 파일에 매니페스트가 없으면 나를 위해 작동합니다.


이 오류가 발생했는데 인수 순서가 잘못 되었기 때문입니다.

옳은

java maui.main.Examples tagging -jar maui-1.0.jar 

잘못된

java -jar maui-1.0.jar maui.main.Examples tagging 

적절한 매니페스트 파일과 함께 실행 가능한 JAR 파일을 올바르게 만들 었는지 확인하는 가장 쉬운 방법은 Eclipse사용 하여 빌드하는 것입니다. Eclipse 프로젝트에서 기본적으로 메뉴에서 파일 / 내보내기를 선택하고 프롬프트를 따릅니다.

이렇게하면 JAR 파일이 올바른지 확인할 수 있으며 여전히 문제가있는 경우 다른 곳을 살펴볼 수 있습니다. 이 프로세스는 FAQ에 자세히 설명되어 있습니다. 독립 실행 형 SWT 프로그램을위한 실행 가능한 JAR 파일을 어떻게 생성합니까? .


나는 또한 NetBeans 에서이 오류가 있음을 발견했습니다. 다음이 도움이 되었기를 바랍니다.

  1. 프로젝트 구성으로 이동할 때 실행하려는 기본 클래스를 설정했는지 확인하십시오.
  2. 빌드 또는 클린 빌드 수행
  3. Place the jar file where you wish and try: java -jar "YourProject.jar" again at the command line.

This was the problem I was getting because I had other "test" programs I was using in NetBeans and I had to make sure the Main Class under the Run portion of the Project configuration was set correctly.

many blessings, John P


I was getting the same error when i ran:
jar cvfm test.jar Test.class Manifest.txt

What resolved it was this:
jar cvfm test.jar Manifest.txt Test.class

My manifest has the entry point as given in oracle docs (make sure there is a new line character at the end of the file):
Main-Class: Test


Try

java -cp .:mail-1.4.1.jar JavaxMailHTML 

no need to have manifest file.


I faced the same problem. This unix command is not able to find the main class. This is because the runtime and compile time JDK versions are different. Make the jar through eclipse after changing the java compiler version. The following link helped me.

http://crunchify.com/exception-in-thread-main-java-lang-unsupportedclassversionerror-comcrunchifymain-unsupported-major-minor-version-51-0/

Try running the jar created after this step and then execute it


If your class path is fully specified in manifest, maybe you need the last version of java runtime environment. My problem fixed when i reinstalled the jre 8.


If you using eclipse, try below: 1. Right click on the project -> select Export 2. Select Runnable Jar file in the select an export destination 3. Enter jar's name and Select "Package required ... " (second radio button) -> Finish

Hope this helps...!

참고URL : https://stackoverflow.com/questions/2591516/why-has-it-failed-to-load-main-class-manifest-attribute-from-a-jar-file

반응형