jar包方式运行web项目文件上传和访问

本文介绍了如何在SpringBoot2.x项目中,通过java -jar方式运行实现文件上传和访问。首先,需在maven的pom.xml中添加spring-boot-maven-plugin插件来正确打包jar,解决缺少主清单属性的问题。然后,通过maven install命令生成jar包。在application.properties配置文件中设置文件上传路径(例如F:/wc)和静态资源位置。最后,在代码中指定上传文件的路径以完成功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spingBoot2.x使用 java -jar运行方式的图片上传和访问处理

1.打包成jar包,需要增加maven依赖
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
        如果没加相关依赖,执行maven打包,运行后会报错:no main manifest attribute, in XXX.jar

项目打jar包

点击项目----右键---Run as----maven install

如果在打包jar文件出现No compiler is provided in this environment错误,参考博客

https://blog.youkuaiyun.com/lslk9898/article/details/73836745

生成的jar包路径:

运行jar 文件

进到windows命令行窗口

 

 

 

 

 

 

2.文件上传和访问需要指定磁盘路径
            application.properties中增加下面配置
            1) web.images-path=F:/wc
            2) spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/test/,file:${web.upload-path} 

 

3.在代码里面指定上传文件的路径

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值