idea中将项目打成jar包并在其他项目中引用
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.
点击File -> 点击Project Structure…
然后点击Artifact -> 点击左上角 + 号
然后选择JAR -> From modules with dependencies…
然后选择方法的主类路径 ->选择完路径后点击ok
然后点击Apply -> ok
打包到此结束,然后该Build了,不进行Build不会有jar包
Build构建jar包
点击工具栏的Build -> Build Artifacts…
选择Build
然后生成的jar文件就会在当前项目的out目录下
现有项目引入刚刚打好的jar包
点击File -> 点击Project Structure… ->点击Libraries - > 点击左上角 + 号 -> 点击java选择刚刚打好的jar包引入即可。
注意事项:注意第一步的时候一定要选择From modules with dependencies…,不然不会把原项目的依赖打到jar里面,在其他项目就运行不了了。
修改pom.xml
<resources>
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
<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>
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK