spring项目使用maven打包时,将生成的jar复制到指定路径

使用maven打包jar的时候,默认是把各个项目的jar输入到各自的target目录下。而如果一个项目中包含有N个子项目,人工去把一个个的jar复制出来就太蛋疼了,好在maven有一个maven-antrun-plugin提供了集中复制jar包到指定文件夹的功能。具体用法如下:

test是父项目,hello和helloworld是test的子项目,child1ofhello是hello的子项目
-test
 |-hello
 | |
 | |-child1ofhello
 |
 |-helloworld
  

在父项目的pom.xml中添加以下内容

<properties>
<!-- properties中定义jar包的保存路径-->
<project.jar.output.directory>D:\Documents\sourcecode\Java\test\target2</project.jar.output.directory>
</properties>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                	<!-- 在maven进行package的时候执行-->
                    <phase>package</phase>  
                    <configuration>
                        <tasks>
                        	<!--jar包保存位置 -->
                            <copy todir="${project.jar.output.directory}"> 
                            	<!--antrun自动生成的配置文件的保存位置,这里默认是父项目的target文件夹 -->
                                <fileset dir="${project.build.directory}">
                                    <include name="*.jar" />
                                </fileset>
                            </copy>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

设置好用使用maven进行package,可以看到在jar包全部被复制到了父项目的指定目录
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将Vue应用打包jar,并在Spring Boot项目中引用,您可以使用frontend-maven-plugin插件来执行这个任务。下面是一些步骤可以帮助您实现这个目标: 1. 在您的Vue项目根目录下创建一个`pom.xml`文件,并添加以下配置: ```xml <build> <plugins> <!-- frontend-maven-plugin配置 --> <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.12.0</version> <executions> <!-- 安装 Node.js 和 NPM --> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <configuration> <nodeVersion>v14.17.3</nodeVersion> <npmVersion>6.14.13</npmVersion> </configuration> </execution> <!-- 安装 Vue 依赖 --> <execution> <id>npm install</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>install</arguments> </configuration> </execution> <!-- 执行 Vue 打包 --> <execution> <id>npm run build</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>run build</arguments> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 请注意,您需要根据您的项目需求调整`nodeVersion`和`npmVersion`的版本号。 2. 打开终端并导航到您的Vue项目根目录,运行以下命令将Vue应用打包: ```shell mvn clean install ``` 这个命令将触发frontend-maven-plugin插件的执行,它将安装Node.js和NPM,安装Vue依赖,并执行Vue打包。 3. 打包成功后,您将在`target`目录下找到生成jar文件。将该jar文件复制到您的Spring Boot项目中,并将其作为依赖添加到Spring Boot项目的`pom.xml`文件中。 ```xml <dependency> <groupId>your.groupId</groupId> <artifactId>your-artifactId</artifactId> <version>your-version</version> <scope>runtime</scope> </dependency> ``` 请记得将`your.groupId`、`your-artifactId`和`your-version`替换为您实际的值。 4. 在Spring Boot项目中,您可以使用`org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration`类中的`addResourceHandlers()`方法来配置静态资源的处理。添加以下代码: ```java @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**") .addResourceLocations("classpath:/static/") .setCachePeriod(0); } } ``` 这将使Spring Boot能够正确地处理静态资源路径。 现在,您可以重新构建并运行Spring Boot项目,Vue应用将作为静态资源打包jar中,并能够在Spring Boot应用中访问。 请注意,这只是一种将Vue应用打包jar并在Spring Boot项目中引用的方法。根据您的具体需求和项目结构,可能需要进行一些调整和修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值