gpt4 book ai didi

drools - Optaplanner 7.13.0 无法从 jar 文件执行

转载 作者:行者123 更新时间:2023-12-03 08:58:22 27 4
gpt4 key购买 nike

我正在使用 optaplanner jar 构建一个项目来解决车辆路径问题。构建 jar 后,我无法调用主类,这是我得到的错误:

513 [main] INFO org.kie.api.internal.utils.ServiceDiscoveryImpl - Loading kie.conf from  jar:file:/Users/meena/Documents/SourceCode/Comma_code/comma_code/sources/target/comma-1.0-SNAPSHOT-jar-with-dependencies.jar!/META-INF/kie.conf in classloader sun.misc.Launcher$AppClassLoader@55f96302
515 [main] INFO org.kie.api.internal.utils.ServiceDiscoveryImpl - Adding Service +org.optaplanner.core.impl.solver.kie.KieSolverAssemblerService

Exception in thread "main" java.lang.ExceptionInInitializerError
at org.kie.api.internal.utils.ServiceRegistry.getInstance(ServiceRegistry.java:27)
at org.kie.api.KieServices$Factory$LazyHolder.<clinit>(KieServices.java:332)
at org.kie.api.KieServices$Factory.get(KieServices.java:339)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:499)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:350)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:255)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61)
at com.abc.planner.app.UavRoutingApp.<init>(UavRoutingApp.java:57)
at com.abc.planner.app.UavRoutingApp.main(UavRoutingApp.java:110)
Caused by: java.lang.RuntimeException: Child services [org.kie.api.internal.assembler.KieAssemblers] have no parent
at org.kie.api.internal.utils.ServiceDiscoveryImpl.buildMap(ServiceDiscoveryImpl.java:180)
at org.kie.api.internal.utils.ServiceDiscoveryImpl.getServices(ServiceDiscoveryImpl.java:97)
at org.kie.api.internal.utils.ServiceRegistryImpl.<init>(ServiceRegistryImpl.java:36)
at org.kie.api.internal.utils.ServiceRegistryImpl$LazyHolder.<clinit>(ServiceRegistryImpl.java:32)
... 9 more

我研究了 Stackoverflow 问题,但无法找到解决该问题的解决方案。

这是我的 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>com.abc</groupId>
<artifactId>proj_xyz</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>comma</name>
<url>http://www.barnstormresearch.com</url>

<!-- see https://www.optaplanner.org/download/download.html for planner version and mvn dependency
-->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
<version>7.13.0.Final</version>
</dependency>
<!--dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-persistence-common</artifactId>
<version>7.13.0.Final</version>
</dependency-->
<dependency><!-- Most examples use the XStream integration -->
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-persistence-xstream</artifactId>
<version>7.13.0.Final</version>
</dependency>
<!--dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-benchmark</artifactId>
<version>7.13.0.Final</version>
</dependency-->
<!--dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>7.12.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>7.12.0.Final</version>
<scope>runtime</scope>
</dependency-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<sourceDirectory>src/main/java</sourceDirectory>

<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<!-- set the java version -->
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<!--plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin-->
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>
com.abc.planner.app.UavRoutingApp
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

它是从 IDE 执行的。我已经提取了 jar 文件,只发现 1 META_INF/kie.conf

任何想法都非常感激。

谢谢

最佳答案

这看起来像是一个流口水和 Uber-jar(或 fat-jar 或 one-jar)问题。我在 drools 文档网站上找到了这个:

https://docs.jboss.org/drools/release/7.14.0.Final/drools-docs/html_single/index.html#_building_and_running_drools_in_a_fat_jar

这是一个比其他一些建议更简单的修复。

我进行了此处建议的更改,并使用 Maven Shade 插件构建了一个 jar,现在它可以工作了。我正在为将遇到此问题的其他用户粘贴我的示例 pom 文件:

将其添加到 maven-shade-plugin 部分:

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/kie.conf</resource>
</transformer>

我的最终 pom.xml

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.abc.planner.app.UavRoutingApp</mainClass>

<!-- -Dlog4j.configurationFile=../properties/idStrikeSolver-log4j.properties -Duser.timezone="UTC" -->
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/kie.conf</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

希望这对其他人也有帮助!感谢杰弗里的帮助。

关于drools - Optaplanner 7.13.0 无法从 jar 文件执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53199223/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com