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

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

1.打包成jar包,需要增加maven依赖
        
            
                
                    org.springframework.boot
                    spring-boot-maven-plugin
                

            

        

        如果没加相关依赖,执行maven打包,运行后会报错:no main manifest attribute, in XXX.jar

项目打jar包

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

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

https://blog.csdn.net/lslk9898/article/details/73836745

生成的jar包路径:

jar包方式运行web项目文件上传和访问_第1张图片

运行jar 文件

进到windows命令行窗口
jar包方式运行web项目文件上传和访问_第2张图片

 

jar包方式运行web项目文件上传和访问_第3张图片

 

jar包方式运行web项目文件上传和访问_第4张图片

 

jar包方式运行web项目文件上传和访问_第5张图片

 

 

 

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.在代码里面指定上传文件的路径

jar包方式运行web项目文件上传和访问_第6张图片

 

你可能感兴趣的:(Springboot2.x)