最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot本地調(diào)試沒問題,打包運(yùn)行報錯原因及分析

 更新時間:2023年05月19日 16:55:53   作者:yuanshiren133  
這篇文章主要介紹了springboot本地調(diào)試沒問題,打包運(yùn)行報錯原因及分析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

springboot本地調(diào)試沒問題,打包運(yùn)行報錯原因分析

如果引用了本地jar包或者so庫

.dll庫等文件,需要在打包的時候都加載進(jìn)去。

如下圖:本地正常,打包的時候謹(jǐn)記,需要打包進(jìn)去,怎么驗證是否打包成功呢?我們繼續(xù)看打包后的圖片。

把jar包后綴改成zip 格式的,打開壓縮文件,框內(nèi)路徑,查看libs下的包是否在里面可以找到。

如果可以找到就是打包進(jìn)去了,找不到的話,就是沒打包進(jìn)去,稍后我們再說怎么打包進(jìn)去。

動態(tài)庫也打包進(jìn)去了。

 

動態(tài)庫打包進(jìn)去方式如下

 
import org.opencv.core.Core;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @author Arthur.yu
 * @date 2021/12/8 0008
 */
@Configuration
public class NativeConfig {
    static {
    }
    @Bean
    public void loadLib() {
        //根據(jù)操作系統(tǒng)判斷,如果是linux系統(tǒng)則加載c++方法庫
        String systemType = System.getProperty("os.name");
        String ext = (systemType.toLowerCase().indexOf("win") != -1) ? ".dll" : ".so";
//        if (ext.equals(".so")) {
            try {
                NativeLoader.loader("native");
            } catch (Exception e) {
                System.out.println("加載so庫失敗");
            }
//        }else {
//            System.out.println("load --- dll === sucess");
//        }
        System.out.println("loaded");
    }
}
 
import java.io.*;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
 * @author Arthur.yu
 * @date 2021/12/8 0008
 */
public class NativeLoader {
    /**
     * 加載項目下的native文件,DLL或SO
     *
     * @param dirPath 需要掃描的文件路徑,項目下的相對路徑
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public synchronized static void loader(String dirPath) throws IOException, ClassNotFoundException {
        Enumeration<URL> dir = Thread.currentThread().getContextClassLoader().getResources(dirPath);
        // 獲取操作系統(tǒng)類型
        String systemType = System.getProperty("os.name");
        //String systemArch = System.getProperty("os.arch");
        // 獲取動態(tài)鏈接庫后綴名
        String ext = (systemType.toLowerCase().indexOf("win") != -1) ? ".dll" : ".so";
        while (dir.hasMoreElements()) {
            URL url = dir.nextElement();
            String protocol = url.getProtocol();
            if ("jar".equals(protocol)) {
                JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
                JarFile jarFile = jarURLConnection.getJarFile();
                // 遍歷Jar包
                Enumeration<JarEntry> entries = jarFile.entries();
                while (entries.hasMoreElements()) {
                    JarEntry jarEntry = entries.nextElement();
                    String entityName = jarEntry.getName();
                    if (jarEntry.isDirectory() || !entityName.startsWith(dirPath)) {
                        continue;
                    }
                    if (entityName.endsWith(ext)) {
                        loadJarNative(jarEntry);
                    }
                }
            } else if ("file".equals(protocol)) {
                File file = new File(url.getPath());
                loadFileNative(file, ext);
            }
        }
    }
    private static void loadFileNative(File file, String ext) {
        if (null == file) {
            return;
        }
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (null != files) {
                for (File f : files) {
                    loadFileNative(f, ext);
                }
            }
        }
        if (file.canRead() && file.getName().endsWith(ext)) {
            try {
                System.load(file.getPath());
                System.out.println("加載native文件 :" + file + "成功!!");
            } catch (UnsatisfiedLinkError e) {
                System.out.println("加載native文件 :" + file + "失敗!!請確認(rèn)操作系統(tǒng)是X86還是X64!!!");
            }
        }
    }
    /**
     * @throws IOException
     * @throws ClassNotFoundException
     * @Title: scanJ
     * @Description 掃描Jar包下所有class
     */
    /**
     * 創(chuàng)建動態(tài)鏈接庫緩存文件,然后加載資源文件
     *
     * @param jarEntry
     * @throws IOException
     * @throws ClassNotFoundException
     */
    private static void loadJarNative(JarEntry jarEntry) throws IOException, ClassNotFoundException {
        File path = new File(".");
        //將所有動態(tài)鏈接庫dll/so文件都放在一個臨時文件夾下,然后進(jìn)行加載
        //這是應(yīng)為項目為可執(zhí)行jar文件的時候不能很方便的掃描里面文件
        //此目錄放置在與項目同目錄下的natives文件夾下
        String rootOutputPath = path.getAbsoluteFile().getParent() + File.separator;
        String entityName = jarEntry.getName();
        String fileName = entityName.substring(entityName.lastIndexOf("/") + 1);
        System.out.println(entityName);
        System.out.println(fileName);
        File tempFile = new File(rootOutputPath + File.separator + entityName);
        // 如果緩存文件路徑不存在,則創(chuàng)建路徑
        if (!tempFile.getParentFile().exists()) {
            tempFile.getParentFile().mkdirs();
        }
        // 如果緩存文件存在,則刪除
        if (tempFile.exists()) {
            tempFile.delete();
        }
        InputStream in = null;
        BufferedInputStream reader = null;
        FileOutputStream writer = null;
        try {
            //讀取文件形成輸入流
            in = NativeLoader.class.getResourceAsStream(entityName);
            if (in == null) {
                in = NativeLoader.class.getResourceAsStream("/" + entityName);
                if (null == in) {
                    return;
                }
            }
            NativeLoader.class.getResource(fileName);
            reader = new BufferedInputStream(in);
            writer = new FileOutputStream(tempFile);
            byte[] buffer = new byte[1024];
            while (reader.read(buffer) > 0) {
                writer.write(buffer);
                buffer = new byte[1024];
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            if (in != null) {
                in.close();
            }
            if (writer != null) {
                writer.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            System.out.println("path :" + tempFile.getPath());
            System.load(tempFile.getPath());
            System.out.println("加載native文件 :" + tempFile + "成功!!");
        } catch (UnsatisfiedLinkError e) {
            System.out.println("加載native文件 :" + tempFile + "失敗!!請確認(rèn)操作系統(tǒng)是X86還是X64!!!");
        }
    }
}

運(yùn)行的時候,會在jar包所在目錄生成一個native文件夾,里面放的就是動態(tài)庫

下面我們看一下本地jar包怎么打進(jìn)去

jar包存放路徑

pom 文件引用一下 

        <dependency>
            <groupId>org.opencv</groupId>
            <artifactId>opencv</artifactId>
            <version>0.0.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/opencv-343.jar</systemPath>
        </dependency>

pom打包配置

<build>
        <plugins>
            <!--參考文章:https://blog.csdn.net/liupeifeng3514/article/details/80236077-->
            <plugin>
                <!-- 指定maven編譯的jdk版本,如果不指定,maven3默認(rèn)用jdk 1.5 maven2默認(rèn)用jdk1.3 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <!-- 源代碼使用的JDK版本 -->
                    <source>1.8</source>
                    <!-- 需要生成的目標(biāo)class文件的編譯版本 -->
                    <target>1.8</target>
                    <!-- 字符集編碼 -->
                    <encoding>UTF-8</encoding>
                    <!-- 跳過測試 -->
                    <skip>true</skip>
                    <compilerArguments>
                        <extdirs>${project.basedir}/libs</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>${project.basedir}/libs/</directory>
                <targetPath>BOOT-INF\lib</targetPath>
               <includes>
                      <include>**/*.jar</include>
                  </includes>
            </resource>
            <resource>
                <directory>${project.basedir}/libs</directory>
            </resource>
        </resources>
    </build>

好了。動態(tài)庫跟jar包都打包進(jìn)去了。

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • String類型傳遞是值傳遞,char[]類型傳遞是引用傳遞的實現(xiàn)

    String類型傳遞是值傳遞,char[]類型傳遞是引用傳遞的實現(xiàn)

    下面小編就為大家?guī)硪黄猄tring類型傳遞是值傳遞,char[]類型傳遞是引用傳遞的實現(xiàn)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看不
    2016-09-09
  • JavaCV實現(xiàn)將視頻以幀方式抽取

    JavaCV實現(xiàn)將視頻以幀方式抽取

    這篇文章主要為大家詳細(xì)介紹了JavaCV實現(xiàn)將視頻以幀方式抽取,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Java集合和數(shù)組的區(qū)別

    Java集合和數(shù)組的區(qū)別

    本文主要介紹了Java集合和數(shù)組的區(qū)別。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • Netty學(xué)習(xí)之理解selector原理示例

    Netty學(xué)習(xí)之理解selector原理示例

    這篇文章主要為大家介紹了Netty學(xué)習(xí)之理解selector原理示例使用分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>
    2023-07-07
  • Java字符串的基礎(chǔ)用法解讀

    Java字符串的基礎(chǔ)用法解讀

    本文將帶您深入了解?Java?字符串的特性、用法以及一些高級技巧,幫助您在編程實踐中更加得心應(yīng)手,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-05-05
  • Java算法之位圖的概念和實現(xiàn)詳解

    Java算法之位圖的概念和實現(xiàn)詳解

    這篇文章主要介紹了Java算法之位圖的概念和實現(xiàn)詳解,位圖可以利用每一位來對應(yīng)一個值,比如可以利用int類型的數(shù)去存儲0~31這個集合的數(shù)字,如果該集合內(nèi)的數(shù)字存在,則把對應(yīng)的位設(shè)置位1默認(rèn)為0,需要的朋友可以參考下
    2023-10-10
  • springboot DTO字符字段與日期字段的轉(zhuǎn)換問題

    springboot DTO字符字段與日期字段的轉(zhuǎn)換問題

    這篇文章主要介紹了springboot DTO字符字段與日期字段的轉(zhuǎn)換問題,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-07-07
  • java jdk動態(tài)代理詳解

    java jdk動態(tài)代理詳解

    動態(tài)代理類的Class實例是怎么生成的呢,是通過ProxyGenerator類來生成動態(tài)代理類的class字節(jié)流,把它載入方法區(qū)
    2013-09-09
  • 詳解slf4j+logback在java工程中的配置

    詳解slf4j+logback在java工程中的配置

    這篇文章主要介紹了slf4j+logback在java工程中的配置,對日志組件logback也進(jìn)行了簡單介紹,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2015-08-08
  • 用html css javascript打造自己的RIA圖文教程

    用html css javascript打造自己的RIA圖文教程

    用html&css&javascript打造自己的RIA之一,包括了配置等
    2009-07-07

最新評論

三亚市| 平顶山市| 吴川市| 兰西县| 伊宁市| 新津县| 林西县| 丰宁| 卢氏县| 策勒县| 绥棱县| 磐安县| 宝兴县| 繁昌县| 郸城县| 璧山县| 迭部县| 枣强县| 兴城市| 文成县| 永修县| 平顶山市| 郓城县| 广东省| 平果县| 武宣县| 诸城市| 信丰县| 竹溪县| 渝中区| 巫溪县| 平和县| 阿城市| 措勤县| 思茅市| 绵阳市| 武冈市| 东丰县| 什邡市| 伊金霍洛旗| 卢湾区|