当前位置:网站首页>How does idea package its own projects into jar packages

How does idea package its own projects into jar packages

2022-06-25 21:41:00 Xili xiaozhuge

One 、 Ideas

First, prepare two projects to establish two , A project as provided jar The works of the package , Another project as a call jar The works of the package .( Pay attention to idea The project document in is moudule, instead of project,project It's the workspace ).

Two 、 Create a provider jar Project of the package

1. So let's set up a moudule project , And create a new department class (Dept.java).
 Insert picture description here
2. open Project Structure, Do the following :( Shortcut key ctrl+alt+shift+s)
① choice Artifacts, Click on + Number , Create a new empty one jar Package file
 Insert picture description here
② to jar File naming ( english ), And pack you into jar The works of the package , Drag to the newly named jar On the bag .
 Insert picture description here

 Insert picture description here
③ The following structure will appear , Then apply . Insert picture description here
④ Because we just changed Artifacts Set up , Now we need Build Artifacts. Click on Buid-Buid Artifacts.  Insert picture description here
Then choose what we want Buid Of jar package .
 Insert picture description here
⑤ Go back to the Project Structure Found exported in jar The path of the package , Then in the corresponding path of our computer , We can find the jar It's packed .
 Insert picture description here

 Insert picture description here

3、 ... and 、 Create a project call jar package , Use jar Class files in the package .

1、 The creation of the project is similar to that before . Under the new project , We build a new one TestMain class , Used to test whether it can call Previous export jar In bag Dept class . The specific steps are as follows :

① Copy secondjar.jar package , Paste into call jar Under the project of the package
 Insert picture description here
② Right click secondjar.jar, Click on Add as Library.
 Insert picture description here
③ Then click OK , Now it is added successfully , You can call the classes in the package .
 Insert picture description here

原网站

版权声明
本文为[Xili xiaozhuge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251911411732.html