1. 程式人生 > >jar包方式執行web專案檔案上傳和訪問

jar包方式執行web專案檔案上傳和訪問

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.csdn.net/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.在程式碼裡面指定上傳檔案的路徑