1

我正在尝试从我的 Windows 命令提示符以 java SE 模式运行示例。我已经构建了一个包含所有依赖项的 jar,并从我的命令提示符运行它。

但是,不断收到错误。从这个答案中,我了解到我的运行时类路径中可能有多个 StepContext 类。

我现在用 maven-shade 插件替换了 maven-assembly 插件来构建我的 fat jar,我可以在打包 jar 时看到以下警告

[WARNING] javax.inject-1.jar, weld-se-2.2.15.Final.jar define 6 overlapping classes: 
[WARNING] - javax.inject.Inject 
[WARNING] - javax.inject.Singleton 
[WARNING] - javax.inject.Scope 
[WARNING] - javax.inject.Named 
[WARNING] - javax.inject.Provider 
[WARNING] - javax.inject.Qualifier 

我将以下依赖项更新为提供,现在我在打包时没有看到上述警告,但是在运行新生成的 jar 时仍然出现异常

<dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>provided</scope>
        </dependency>

执行 JAR 文件时的当前异常

Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type InjectionPoint with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Produces @BatchProperty public org.jberet.creation.BatchBeanProducer.getStringList(InjectionPoint)
  at org.jberet.creation.BatchBeanProducer.getStringList(BatchBeanProducer.java:0)
  Possible dependencies:
  - Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default],
  - Managed Bean [class org.jboss.weld.manager.BeanManagerImpl$InstanceInjectionPoint] with qualifiers [@Any @Default],
  - Managed Bean [class org.jboss.weld.injection.EmptyInjectionPoint] with qualifiers [@Any @Default]

        at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:392)
        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:294)
        at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:135)
        at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:168)
        at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:543)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type InjectionPoint with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Produces @BatchProperty public org.jberet.creation.BatchBeanProducer.getStringBuilder(InjectionPoint)
  at org.jberet.creation.BatchBeanProducer.getStringBuilder(BatchBeanProducer.java:0)
  Possible dependencies:
  - Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default],
  - Managed Bean [class org.jboss.weld.manager.BeanManagerImpl$InstanceInjectionPoint] with qualifiers [@Any @Default],
  - Managed Bean [class org.jboss.weld.injection.EmptyInjectionPoint] with qualifiers [@Any @Default]

        at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:392)
        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:294)
        at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:135)
        at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:168)
        at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:543)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
        at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

        at org.jboss.weld.bootstrap.ConcurrentValidator.validateBeans(ConcurrentValidator.java:76)
        at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:504)
        at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:435)
        at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
        at org.jboss.weld.environment.se.Weld.initialize(Weld.java:148)
        at org.jberet.se.SEArtifactFactory.<init>(SEArtifactFactory.java:29)
        at org.jberet.se.BatchSEEnvironment.getArtifactFactory(BatchSEEnvironment.java:133)
        at org.jberet.operations.JobOperatorImpl.<init>(JobOperatorImpl.java:93)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        ... 8 more

我该如何解决这个问题?

4

2 回答 2

0

终于能够使用 JBERET 实现在 Java SE 模式下运行 Java 批处理程序的可执行(胖)JAR。

这个链接提到了这一点,一旦我切换到 2.4.5.Final 它工作正常。

直到最近,嵌套/胖 JAR 才与 Weld 一起使用,直到它在 Weld 2.3.4 中使用 WELD-1930 修复

于 2017-10-05T03:57:54.063 回答
0

在我看来,您的扁平化导致焊接实现最终出现在一个带有 beans.xml 的 jar 中,由于“all”的 bean 发现模式(这也是没有版本的空 beans.xml 的情况)。

如果您要将焊接 impl 塞入一个带有您的应用程序的大 jar 中,您应该最低限度地确保它是 bean-discovery-mode="annotated"。

于 2017-10-04T01:38:50.617 回答