developer tip

Eclipse에 포함 된 외부 라이브러리로 jar를 만드는 방법은 무엇입니까?

optionbox 2020. 9. 14. 08:20
반응형

Eclipse에 포함 된 외부 라이브러리로 jar를 만드는 방법은 무엇입니까?


데이터베이스 (MySQL)에 연결하는 프로젝트를 완료했습니다. 이제 프로젝트를 jar로 내보내고 싶습니다. 하지만 외부 종속성을 포함하는 방법을 모르겠습니까? Eclipse에서 수행하는 방법이 있습니까? 아니면 스크립트를 사용해야합니까?.


프로젝트를 'Runnable jar'로 내보낼 때 (프로젝트에서 마우스 오른쪽 버튼-> Export-> Runnable jar) 생성 된 jar에 모든 종속성을 패키징하는 옵션이 있습니다. 또한 라이브러리를 내보내는 두 가지 다른 방법 (스크린 샷 참조)이 있습니다. 사용할 패키징 방법을 결정할 때 라이선스를 알고 있어야합니다.

패키지 라이브러리

'시작 구성'드롭 다운은 main(String[])메서드가 포함 된 클래스로 채워집니다 . 선택한 클래스는 항아리를 '실행'할 때 시작됩니다.

Exporting as a runnable jar uses the dependencies on your build path (Right mouse on project -> Build Path -> Configure Build Path...). When you export as a 'regular' (non-runnable) jar you can select any file in your project(s). If you have the libraries in your project folder you can include them but external dependencies, for example , cannot be included (for maven projects, search here).


You could use the Export->Java->Runnable Jar to create a jar that includes its dependencies

Alternatively, you could use the fatjar eclipse plugin as well to bundle jars together


You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.


Personally,

None of the answers above worked for me, I still kept getting NoClassDefFound errors (I am using Maven for dependencies). My solution was to build using "mvn clean install" and use the "[project]-jar-with-dependencies.jar" that that command creates. Similarly in Eclipse you can right click the project -> Run As -> Maven Install and it will place the jars in the target folder.


If you want to export all JAR-files of a Java web-project, open the latest generated WAR-file with a ZIP-tool (e.g. 7-Zip), navigate to the /WEB-INF/lib/ folder. Here you will find all JAR-files you need for this project (as listed in "Referenced Libraries").


To generate jar file in eclipse right click on the project for which you want to generate, Select Export>Java>Runnable Jar File,

여기에 이미지 설명 입력

여기에 이미지 설명 입력

Its create jar which includes all the dependencies from Pom.xml, But please make sure license issue if you are using third-party dependency for your application.


While exporting your source into a jar, make sure you select runnable jar option from the options. Then select if you want to package all the dependency jars or just include them directly in the jar file. It depends on the project that you are working on.

그런 다음 java -jar example.jar로 jar를 직접 실행합니다.


독립형 (주요 방법) 자바 프로젝트 인 경우 특정 경로가 아닌 특정 경로가 아닌 프로젝트 내부에 모든 항아리를 넣은 다음 프로젝트를 마우스 오른쪽 버튼으로 클릭-> 내보내기-> 실행 가능한 항아리-> 점심 구성 및 라이브러리 처리를 선택하십시오. 그런 다음 "필요한 라이브러리를 생성 된 jar에 패키징"라디오 버튼 옵션-> 완료를 선택하십시오.

또는

웹 프로젝트가있는 경우 모든 jar를 web-inf / lib 폴더에 넣고 동일한 단계를 수행합니다.

참고 URL : https://stackoverflow.com/questions/11033603/how-to-create-a-jar-with-external-libraries-included-in-eclipse

반응형