当我从NetBeans启动应用程序时,它运行良好。但是当我从jar执行我的申请时,我收到此错误:
无法加载spring应用程序上下文: java.util.concurrent.CompletionException:java.lang.IllegalArgumentException:在META-INF / spring.factories中找不到自动配置类。如果您使用的是自定义包装,请确保该文件正确无误。
这是我的POM:
<?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>infn.lns</groupId>
<artifactId>ConsoleLNSMaven</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>ConsoleLNSMaven</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>lns.MainApp</mainClass>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<opencv.directory>/home/gianfranco/opencv/build/lib</opencv.directory>
<!--<opencv.directory>/home/dmnrserver/opencv/build/lib</opencv.directory>-->
</properties>
<organization>
<name>INFN LNS</name>
</organization>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>de.roskenet</groupId>
<artifactId>springboot-javafx-support</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>org.javassist</groupId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>3.4.1-1.4.1</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.14</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.22.0-GA</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addClasspath>true</addClasspath>
<mainClass>lns.MainApp</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
当我使用此命令运行程序时,它将起作用:
mvn“ -Dexec.args = -Djava.library.path = / home / gianfranco / opencv / build / lib --module-path /home/gianfranco/Scaricati/javafx-sdk-11.0.2/lib-添加模块javafx.controls --add-exports = javafx.graphics / com.sun.javafx.util = ALL-UNNAMED --add-exports = javafx.base / com.sun.javafx.reflect = ALL-UNNAMED- add-exports = javafx.base / com.sun.javafx.beans = ALL-UNNAMED --add-exports = javafx.graphics / com.sun.glass.utils = ALL-UNNAMED --add-exports = javafx.graphics / com.sun.javafx.tk =全部取消命名-classpath%classpath lns.MainApp“ -Dexec.executable = / usr / lib / jvm / java-11-oracle / bin / java进程类org.codehaus.mojo:exec -maven-plugin:1.6.0:exec
但是当我使用它时,它不起作用,它给了我这个错误:
java --module-path /home/gianfranco/Scaricati/javafx-sdk-11.0.2/lib --add-modules = javafx.controls,javafx.fxml,javafx.media,javafx.swing -jar target / ConsoleLNSMaven-1.0.jar
答案 0 :(得分:0)
这是解决方案:
仅在POM.xml中添加插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
pom.xml中的一个属性
<properties>
<start-class>com.xxx.yyy.MainClass</start-class>
</properties>
运行命令
mvn clean package spring-boot:repackage
现在运行您在目标文件夹中创建的jar(现在包括所有依赖项)
java -jar my-service-0.0.1-SNAPSHOT.jar