完全离线使用drools 6 maven体系结构

scyqe7ek  于 2021-07-09  发布在  Java
关注(0)|答案(2)|浏览(428)

我正在使用drools 6.0.1,并利用新的基于maven的体系结构来部署我的规则。
项目的pom如本文末尾所示。
我用参数启动项目 -Dkie.maven.settings.custom="X:\\maven2\\settings.xml" 使用单独的maven存储库来存储drools。下面还显示了settings.xml。
当我运行项目(.java)时,drools内部maven,即 Aether ,仍将中央存储库添加到其内部配置中。这很糟糕,因为显然系统应该脱机运行。
然后运行的输出是:

DEBUG [main] (KieRepositoryImpl.java:91) - KieModule Lookup. ReleaseId de.itm.droolstest:x123:1.0.1 was not in cache, checking classpath
DEBUG [main] (KieRepositoryImpl.java:97) - KieModule Lookup. ReleaseId de.itm.droolstest:x123:1.0.1 was not in cache, checking maven repository
DEBUG [main] (Logs.java:390) - Add publisher: com.google.inject.internal.InjectorImpl@784eb2c

-----[explicit bindings]-------------------------------------------------------
0. ProviderInstanceBinding{key=Key[type=com.google.inject.Injector, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<Injector>}
1. ProviderInstanceBinding{key=Key[type=java.util.logging.Logger, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<Logger>}
2. ProviderInstanceBinding{key=Key[type=org.slf4j.Logger, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<org.slf4j.Logger>}
3. InstanceBinding{key=Key[type=com.google.inject.Stage, annotation=[none]], source=[unknown source], instance=DEVELOPMENT}
[...] (many more lines removed for brevity)
202. ConstructorBinding{key=Key[type=org.apache.maven.lifecycle.internal.LifecycleDebugLogger, annotation=[none]], source=ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]], scope=Scopes.SINGLETON}
-----[implicit bindings]-------------------------------------------------------
-------------------------------------------------------------------------------

 INFO [pool-1-thread-1] (NettyAsyncHttpProvider.java:199) - Number of application's worked threads is 8
DEBUG [pool-1-thread-1] (NettyAsyncHttpProvider.java:948) - 
Non cached request 
DefaultHttpRequest(chunked: false)
HEAD /nexus/content/groups/public/de/droolstest/x123/1.0.1/x123-1.0.1.jar HTTP/1.1
Host: nexus.my-domain.de:8081
Pragma: no-cache
Cache-Control: no-cache, no-store
Accept-Encoding: gzip
Connection: keep-alive
Accept: */*
User-Agent: Aether

using Channel 
[id: 0x0fd71519]

DEBUG [New I/O client worker #1-1] (NettyAsyncHttpProvider.java:1048) - 

Request DefaultHttpRequest(chunked: false)
HEAD /nexus/content/groups/public/de/itm/droolstest/x123/1.0.1/x123-1.0.1.jar HTTP/1.1
Host: nexus.my-domain.de:8081
Pragma: no-cache
Cache-Control: no-cache, no-store
Accept-Encoding: gzip
Connection: keep-alive
Accept: */*
User-Agent: Aether

Response DefaultHttpResponse(chunked: false)
HTTP/1.1 404 The server has not found anything matching the request URI
Date: Tue, 11 Mar 2014 09:42:48 GMT
Set-Cookie: rememberMe=deleteMe; Path=/nexus; Max-Age=0; Expires=Mon, 10-Mar-2014 09:42:48 GMT
Date: Tue, 11 Mar 2014 09:42:48 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1533

DEBUG [New I/O client worker #1-1] (NettyConnectionsPool.java:147) - Adding uri: http://nexus.my-domain.de:8081 for channel [id: 0x0fd71519, /192.168.100.113:51272 => nexus.my-domain.de/192.168.100.145:8081]
Exception in thread "main" Exception in thread "FileRepositoryConnector-1" java.lang.IllegalArgumentException: number of transferred bytes cannot be negative
    at org.sonatype.aether.util.listener.DefaultTransferEvent.setTransferredBytes(DefaultTransferEvent.java:123)
    at org.sonatype.aether.connector.file.FileRepositoryWorker.run(FileRepositoryWorker.java:299)
    at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
java.lang.IllegalArgumentException: number of transferred bytes cannot be negative
    at org.sonatype.aether.util.listener.DefaultTransferEvent.setTransferredBytes(DefaultTransferEvent.java:123)
    at org.sonatype.aether.connector.file.FileRepositoryWorker.run(FileRepositoryWorker.java:299)
    at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

(当然,工件在x:/maven2存储库中)
如您所见,系统尝试连接到我们自己的nexus,这是在global中配置的 settings.xml ,一个用来建造这个项目的。
因此,我的问题是:如何配置drools使其maven完全脱机运行如何防止drools的maven执行项目的任务 pom.xml 作为配置?那个 pom.xml 应该只在构建项目时使用,而不是在运行时使用!这能预防吗?
感谢您的帮助!
现在是配置文件。
项目的 pom.xml :

<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>de.demo</groupId>
    <artifactId>kieTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.drools</groupId>
                <artifactId>drools-bom</artifactId>
                <type>pom</type>
                <version>6.0.1.Final</version>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</project>

这个 x:\maven2\settings.xml (流口水的那个):

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <localRepository>x:/maven2/repository</localRepository>
    <interactiveMode>false</interactiveMode>
    <offline>true</offline>

    <profiles>
        <profile>
            <id>droolsOffline</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://repo1.maven.org/maven2</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>    
            </repositories>
        </profile>
    </profiles>
</settings>

实际的java类:package-kietest;

import org.kie.api.*;

public class MainKieTest {

    public static void main(String[] args) {
        KieServices ks = KieServices.Factory.get();
        KieRepository repository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("de.test.droolstest", "x123", "1.0.1");
        KieContainer kieContainer = ks.newKieContainer(releaseId);
    }
}
sqyvllje

sqyvllje1#

nexus包含发布工件是正常的,而不仅仅是构建期间使用的依赖项。但是,有可能阻止它的使用。大概您的~/.m2/.settings.xml已配置为在查找工件时转到nexus存储库而不是中心。与将maven配置为转到nexus代理而不是central的方法类似,只需更改~/.m2/.settings即可禁用从central下载版本和快照工件。

<repositories>
  <repository>
    <id>central</id>
    <url>http://repo1.maven.org/maven2</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
</repositories>
oaxa6hgo

oaxa6hgo2#

我发现了潜在的问题:在redhat的bugzilla中的BugNo.1065984。它是关于嵌入的maven不尊重在显式中配置的设置 settings.xml . 这个错误修复是在drools 6.1.0.beta1中发布的,该版本于上周五在maven存储库中发布——这就是为什么我很快才找到它的原因。
在新版本中,离线方面工作得更好,至少不会像这样连接到远程服务器。
不过,还有一个问题,即有效的maven配置/pom确实考虑到了用于drools项目的pom正在内部运行。这很糟糕,因为我不想把所有这些依赖项都放到droolmaven存储库中。但这是另一个问题。

相关问题