Error: Unable to access jarfile xxx.jar

Error: Unable to access jarfile xxx.jar 解决

Today, a colleague encountered this exception. By the way, the SpringBoot project install is compiled to get the xxx.jar package. Through the startup script in the virtual machine server, an exception is thrown at startup: Error: Unable to access jarfile xxx.jar , how to solve it ?

Exception information:


[pepp@Memcache_HA_TEST xxl_job_management]$
[pepp@Memcache_HA_TEST xxl_job_management]$ /u01/app/jdk1.8/bin/java -jar xxl_job_management-1.0.0-RELEASE.2022111714113443.jar
Error: Unable to access jarfile xxl_job_management-1.0.0-RELEASE.2022111714113443.jar
[pepp@Memcache_HA_TEST xxl_job_management]$
[pepp@Memcache_HA_TEST xxl_job_management]$

picture:
insert image description here

Solution:
insert image description here
Add dependencies to the pom.xml file

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

Reason:
In the SpringBoot project, the framework provides its own packaging mechanism, which is implemented through the spring-boot-maven-plugin plug-in. It can be repackaged after MAVEN's life cycle package to generate a new JAR package. The spring-boot-maven-plugin plug-in packages the SpringBoot project into a FAT-JAR, that is to say, it includes all the JARs needed to start and run the project.
Add the jar structure packaged by the spring-boot-maven-plugin plugin:

insert image description here

target Currently, you can see that two jar related files have been generated, among which xxl_job_management-1.0.0-RELEASE.jar is the executable jar generated after repackaging the spring-boot-maven-plugin plug-in, which can be passed java -jar xxl_job_management-1.0 The .0-RELEASE.jar command starts. xxl_job_management-1.0.0-RELEASE.jar.original This package is the original jar packaged by mvn package. It is renamed to xxx.original when the spring-boot-maven-plugin plug-in repackage command operates. This is an ordinary jar that can be References in other services.

Guess you like

Origin blog.csdn.net/jiuyuemo1/article/details/127903873