springboot实现图片上传之打jar包(三)

1在pom.xml中添加Maven的依赖,如果没有对应的依赖,运行后会报错:no main mainfest attribute,in xxx.jar

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

2鼠标右键点击项目,然后选择Run as下的mvn install

3文件上传和需要制定的磁盘路径

  application.properties中添加以下配置

     web.images-path可以自定义, 路径是服务器的路径

    spring.resources.static-locations是静态资源的路径,file:${web.upload-path}是读取当前配置文件中的路径

web.images-path=G:study_toolmaven_workspaceimages
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/test/,file:${web.upload-path}

然后将fileController中的路径改为application.properties中的web.images-path即可

4打包成功的话,这个时候会在项目中的target目录下面生成一个xxxx-0.0.1-SNAPSHOT.jar

   可以通过GUI(反编译工具将jar反编译为class文件,方便阅读)

   或者直接改尾椎,将jar改为zip,然后双击解压

5打开cmd,找到对应的target所在位置,运行java -jar  xxxx-0.0.1-SNAPSHOT.jar

6本地打包,线上运行就是将这个jar包通过xfttp传到阿里云上面去,然后通过xshell运行这个jar包即可

7可以通过阿里云oss,nginx来搭建一个简单的图片服务器

原文地址:https://www.cnblogs.com/zhushilai/p/13518633.html