date | author | edition | remarks |
---|---|---|---|
2020-09-27 | dingbin | V1.0 | |
maven Introduce local jar Package problem from 3 Consider the following aspects :
1. IDE Tools such as Jetbrains IDEA consider :
In turn, open IDEA Of File – Project Structure – Project Settings – Modules –
Dependencies Tab area , Click on the top right corner + Number icon , choice 1.JARS or
directories…, Re selection java Project root directory lib or libs Under the table of contents , Bring in all the things that need to be introduced locally jar Choose more bags ,
And then click OK that will do .
2. Maven Compiler level considerations :
stay pom.xml In file dependencies At the end of the component, add the local dependency as shown in the figure below jar package .
Be careful scope by system Means local jar package .
systemPath For local paths , Be sure to use \${project.basedir}/ Introduce... At the beginning , In order to show the general type .
above 3 After the modification of this place , The effect of the combination is ,mvn clean package
Later meeting target Create one in the directory lib Catalog , And put all the remote jar Bag and local jar All the packages are copied to lib Under the table of contents , For later java Find it when the program is running . Pay attention to the local jar The green box in the above figure will be named in lib Under the table of contents .
Above picture \<addClasspath\>true\</addClasspath\> Indicates the target that will be generated jar In file MANIFEST.MF Add classpath Here's the picture ,\<classpathPrefix\>lib\</classpathPrefix\>
Show that you will give MANIFEST.MF Medium classpath Every one of them classpath Add a prefix lib. These features are very important .
therefore \<plugins\>\</plugins\> There are 3 term :
With vim Open the generated target jar package vi mylucenedemo.jar: after :
The cursor is on MANIFEST.MF Press enter , You can see :
Besides , If necessary ,java Project objectives jar It may also depend on some configuration files , adopt pom.xml in profiles Under the profile Copy it to target In the catalog conf Go to the catalogue :
The effect is as follows :
3. The goal is jar At the level of procedure implementation, we should consider :
Next , You can go to java The project is executed in the root directory :mvn clean install -U, It will generate the following target Catalog , What's useful is conf Catalog ,lib Directory and target file mylucenedemo.jar.
How to implement it : stay target Direct execution under directory java -jar mylucenedemo.jar that will do .
Will automatically read under the current account lib All dependencies of subdirectories jar package , Including the introduction of local jar package . as well as conf All configuration files in the directory .
Last , Another example pox.xml: pom.xml, Extraction code :h1e1.