2

idea中将项目打成jar包并在其他项目中引用

 1 year ago
source link: https://blog.51cto.com/u_15430445/5819749
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

 点击File -> 点击Project Structure…

idea中将项目打成jar包并在其他项目中引用_jar

 然后点击Artifact -> 点击左上角 + 号

idea中将项目打成jar包并在其他项目中引用_java_02

然后选择JAR -> From modules with dependencies…

idea中将项目打成jar包并在其他项目中引用_jar包_03

 然后选择方法的主类路径 ->选择完路径后点击ok

idea中将项目打成jar包并在其他项目中引用_jar包_04

然后点击Apply -> ok

idea中将项目打成jar包并在其他项目中引用_jar_05

打包到此结束,然后该Build了,不进行Build不会有jar包

Build构建jar包

 点击工具栏的Build -> Build Artifacts…

idea中将项目打成jar包并在其他项目中引用_jar包_06

 选择Build

idea中将项目打成jar包并在其他项目中引用_jar_07

 然后生成的jar文件就会在当前项目的out目录下

idea中将项目打成jar包并在其他项目中引用_jar_08

现有项目引入刚刚打好的jar包

 点击File -> 点击Project Structure… ->点击Libraries - > 点击左上角 + 号 -> 点击java选择刚刚打好的jar包引入即可。

idea中将项目打成jar包并在其他项目中引用_jar包_09

注意事项:注意第一步的时候一定要选择From modules with dependencies…,不然不会把原项目的依赖打到jar里面,在其他项目就运行不了了。

修改pom.xml

<!--引入本地jar资源-->
<resources>
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
<dependency>
<groupId>com.pj</groupId>
<artifactId>sp-generate</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sp-generate.jar</systemPath>
</dependency>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK