Jar 文件在 Windows 上完美运行,但在 Rasp Pi 内的 Ubuntu 上运行失败

Posted

技术标签:

【中文标题】Jar 文件在 Windows 上完美运行,但在 Rasp Pi 内的 Ubuntu 上运行失败【英文标题】:Jar file runs perfectly on Windows, but failed on Ubuntu inside Rasp Pi 【发布时间】:2021-12-28 06:29:51 【问题描述】:

这是我的 discord 音乐播放器机器人,我使用 Maven 和 Java 8 编译并安装了它,过程如下:

mvn clean
mvn compile
mvn test-compile
mvn test
mvn install

这是我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.jagrosh</groupId>
    <artifactId>JMusicBot</artifactId>
    <version>Snapshot</version>
    <packaging>jar</packaging>
    
    <repositories>
        <repository>
            <id>dv8tion</id>
            <name>m2-dv8tion</name>
            <url>https://m2.dv8tion.net/releases</url>
        </repository>
        <repository>
            <id>central</id>
            <name>bintray</name>
            <url>https://jcenter.bintray.com</url>
        </repository>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>net.dv8tion</groupId> 
            <artifactId>JDA</artifactId> 
            <version>4.3.0_324</version>
        </dependency>
        <!-- using a fork of this to fix some issues faster -->
        <!-- dependency>
            <groupId>com.sedmelluq</groupId>
            <artifactId>lavaplayer</artifactId>
            <version>1.3.78</version>
        </dependency -->
        <dependency>
        <groupId>com.github.jagrosh</groupId>
        <artifactId>lavaplayer</artifactId>
        <version>jmusicbot-SNAPSHOT</version>
    </dependency>
        <!-- this is needed, but isn't actually hosted anywhere anymore... uh -->
        <!--dependency>
            <groupId>com.sedmelluq</groupId>
            <artifactId>lavaplayer-natives-extra</artifactId>
            <version>1.3.13</version>
        </dependency-->
        <dependency>
            <groupId>com.jagrosh</groupId>
            <artifactId>jda-utilities</artifactId>
            <version>3.0.5</version>
            <type>pom</type>
        </dependency>
        <!-- jitpack for now, we need to version this correctly later -->
    <dependency>
        <groupId>com.github.jagrosh</groupId>
        <artifactId>JLyrics</artifactId>
        <version>-SNAPSHOT</version>
    </dependency>
        <!--dependency>
            <groupId>com.jagrosh</groupId>
            <artifactId>JLyrics</artifactId>
            <version>0.6</version>
        </dependency-->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe</groupId>
            <artifactId>config</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.14.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <build>
      <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>All</shadedClassifierName>
                        <artifactSet>
                            <includes>
                                <include>*:*</include>
                            </includes>
                        </artifactSet>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>reference.conf</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>com.jagrosh.jmusicbot.JMusicBot</Main-Class>
                                    <Specification-Title>$project.artifactId</Specification-Title>
                                    <Specification-Version>$project.version</Specification-Version>
                                    <Implementation-Title>$project.artifactId</Implementation-Title>
                                    <Implementation-Version>$project.version</Implementation-Version>
                                    <Implementation-Vendor-Id>$project.groupId</Implementation-Vendor-Id>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
      </plugins>
    </build>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

在我的 Windows 10 上完美运行

[16:18:35] [INFO] [JDA]: Login Successful!
[16:18:36] [INFO] [WebSocketClient]: Connected to WebSocket
[16:18:37] [INFO] [JDA]: Finished Loading!
[16:19:09] [INFO] [NativeLibraryLoader]: Native library libmpg123-0: loading with filter com.sedmelluq.discord.lavaplayer.natives.ConnectorNativeLibLoader$$Lambda$237/470342757@e75991d
[16:19:09] [INFO] [NativeLibraryLoader]: Native library connector: loading with filter null
[16:19:10] [INFO] [NativeLibraryLoader]: Native library connector: successfully loaded.

但是当它进入我安装了 Ubuntu 的 Raspberry Pi 时,它无法运行。

发送音乐播放命令后发生错误...

[08:20:52] [INFO] [JDA]: Login Successful!
[08:20:53] [INFO] [WebSocketClient]: Connected to WebSocket
[08:20:53] [INFO] [JDA]: Finished Loading!
[08:21:20] [WARN] [RateLimiter]: Encountered 429 on route PATCH/channels/channel_id with bucket 9852e1a53c06ffc5a89d65fef85ca4ce:channel_id=867720908658704385 Retry-After: 467000 ms
[08:21:22] [INFO] [NativeLibraryLoader]: Native library libmpg123-0: loading with filter com.sedmelluq.discord.lavaplayer.natives.ConnectorNativeLibLoader$$Lambda$240/1535558280@629e30f3
[08:21:22] [INFO] [NativeLibraryLoader]: Native library connector: loading with filter null
[08:21:22] [ERROR] [NativeLibraryLoader]: Native library connector: loading failed.
java.lang.UnsatisfiedLinkError: Required library was not found
        at com.sedmelluq.lava.common.natives.NativeLibraryLoader.extractLibraryFromResources(NativeLibraryLoader.java:125)
        at com.sedmelluq.lava.common.natives.NativeLibraryLoader.loadInternal(NativeLibraryLoader.java:110)
        at com.sedmelluq.lava.common.natives.NativeLibraryLoader.loadWithFailureCheck(NativeLibraryLoader.java:84)
        at com.sedmelluq.lava.common.natives.NativeLibraryLoader.load(NativeLibraryLoader.java:69)
        at com.sedmelluq.discord.lavaplayer.natives.ConnectorNativeLibLoader.loadConnectorLibrary(ConnectorNativeLibLoader.java:21)
        at com.sedmelluq.discord.lavaplayer.natives.opus.OpusDecoderLibrary.getInstance(OpusDecoderLibrary.java:13)
        at com.sedmelluq.discord.lavaplayer.natives.opus.OpusDecoder.<init>(OpusDecoder.java:20)
        at com.sedmelluq.discord.lavaplayer.container.common.OpusPacketRouter.initialiseDecoder(OpusPacketRouter.java:193)
        at com.sedmelluq.discord.lavaplayer.container.common.OpusPacketRouter.checkDecoderNecessity(OpusPacketRouter.java:177)
        at com.sedmelluq.discord.lavaplayer.container.common.OpusPacketRouter.process(OpusPacketRouter.java:93)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaOpusTrackConsumer.consume(MatroskaOpusTrackConsumer.java:46)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaStreamingFile.processFrameInBlock(MatroskaStreamingFile.java:371)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaStreamingFile.parseClusterSimpleBlock(MatroskaStreamingFile.java:335)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaStreamingFile.parseNextCluster(MatroskaStreamingFile.java:320)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaStreamingFile.provideFrames(MatroskaStreamingFile.java:296)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaAudioTrack.lambda$process$0(MatroskaAudioTrack.java:39)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.executeProcessingLoop(LocalAudioTrackExecutor.java:275)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.executeProcessingLoop(LocalAudioTrackExecutor.java:249)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaAudioTrack.process(MatroskaAudioTrack.java:38)
        at com.sedmelluq.discord.lavaplayer.track.DelegatedAudioTrack.processDelegate(DelegatedAudioTrack.java:25)
        at com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack.processStatic(YoutubeAudioTrack.java:57)
        at com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack.process(YoutubeAudioTrack.java:49)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.execute(LocalAudioTrackExecutor.java:104)
        at com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager.lambda$executeTrack$1(DefaultAudioPlayerManager.java:348)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
[08:21:22] [ERROR] [LocalAudioTrackExecutor]: Error in playback of 6pEs5DL2UVU
com.sedmelluq.discord.lavaplayer.tools.FriendlyException: Something went wrong when decoding the track.
        at com.sedmelluq.discord.lavaplayer.tools.ExceptionTools.wrapUnfriendlyExceptions(ExceptionTools.java:44)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.executeProcessingLoop(LocalAudioTrackExecutor.java:293)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.executeProcessingLoop(LocalAudioTrackExecutor.java:249)
        at com.sedmelluq.discord.lavaplayer.container.matroska.MatroskaAudioTrack.process(MatroskaAudioTrack.java:38)
        at com.sedmelluq.discord.lavaplayer.track.DelegatedAudioTrack.processDelegate(DelegatedAudioTrack.java:25)
        at com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack.processStatic(YoutubeAudioTrack.java:57)
        at com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack.process(YoutubeAudioTrack.java:49)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.execute(LocalAudioTrackExecutor.java:104)
        at com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager.lambda$executeTrack$1(DefaultAudioPlayerManager.java:348)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        Suppressed: com.sedmelluq.discord.lavaplayer.tools.exception.EnvironmentInformation: 
  lavaplayer.version: 1.3.78
  os.arch: aarch64
  os.name: Linux
  os.version: 5.11.0-1009-raspi
  java.vendor: Private Build
  java.version: 1.8.0_292
  java.runtime.version: 1.8.0_292-8u292-b10-0ubuntu1-b10
  java.vm.version: 25.292-b10

我试过这个方法Change to Cp1252 encoding,但还是失败了。

【问题讨论】:

相关?:How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project 阅读常见问题解答:github.com/sedmelluq/lavaplayer/blob/master/FAQ.md 谢谢,我现在明白了???????????? 这两种log sn-ps有什么区别? 第一个日志是Windows版本,第二个是Linux-ARM 【参考方案1】:

任何人和我有同样的问题,你可以参考这个链接... https://github.com/sedmelluq/lavaplayer/issues/16

或按照我的程序:

使用 WinRaR 或其他可以解压缩 .jar 文件的软件打开 .jar 文件

获取你的平台类型,例如我的平台是树莓派(linux-aarch64)

转到 here 并下载您的平台 libconnector.so

放置它在你解压后的 .jar 文件的路径中 /native/&lt;your_platform&gt;/

【讨论】:

以上是关于Jar 文件在 Windows 上完美运行,但在 Rasp Pi 内的 Ubuntu 上运行失败的主要内容,如果未能解决你的问题,请参考以下文章

C ++程序在Linux上运行完美,但无法在Windows上运行

PHP 站点在 linux 上运行,但在 windows 上不运行

HSQLDB 在 Windows 上运行,但在 Linux 上抛出异常

无法通过在 Azure HDInsight 中运行的 piggybank.jar 使用 PIG 读取 Avro 文件

.jar 文件不适用于 Windows 调度程序

在数据子集上运行但在原始数据上完美运行时出现 h2o 错误