Внедрение зависимостей завершается неудачно в FatJAR с использованием Dropwizard и Weld SE
Я застрял в упаковке простого приложения Dropwizard в FatJar/UberJAR, используя Weld SE для внедрения зависимостей. Вот мой минимальный пример:
Класс приложения
public class WeldApplication extends Application<WeldApplicationsConfiguration> {
public static void main(final String[] args) throws Exception {
new Weld().initialize();
new WeldApplication().run(args);
}
@Override
public String getName() {
return "dw-weld-maven";
}
@Override
public void initialize(final Bootstrap<WeldApplicationsConfiguration> bootstrap) {
// TODO: application initialization
}
@Override
public void run(final WeldApplicationsConfiguration configuration,
final Environment environment) {
// TODO: implement application
}
}
pom.xml
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<groupId>de.playground</groupId>
<artifactId>dw-weld-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>dw-weld-maven</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>1.3.5</dropwizard.version>
<mainClass>de.schweda.playground.WeldApplication</mainClass>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
<!-- exclude signed Manifests -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Ошибки (выдержка)
java -jar dw-weld-maven-1.0-SNAPSHOT.jar server
10:48:41.420 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
10:48:41.424 [main] INFO org.jboss.weld.Version - WELD-000900: SNAPSHOT
10:48:41.466 [main] DEBUG org.jboss.weld.Bootstrap - WELD-ENV-000030: Cannot load class using the ResourceLoader: org.jboss.jandex.Index
10:48:41.546 [main] DEBUG org.jboss.weld.Bootstrap - WELD-ENV-000032: Processing bean archive reference: /home/u142040/Desktop/temp/dw-weld-maven/target/dw-weld-maven-1.0-SNAPSHOT.jar
10:48:41.546 [main] DEBUG org.jboss.weld.environment.deployment.discovery.FileSystemBeanArchiveHandler - Handle path: /home/u142040/Desktop/temp/dw-weld-maven/target/dw-weld-maven-1.0-SNAPSHOT.jar
10:48:41.546 [main] DEBUG org.jboss.weld.environment.deployment.discovery.FileSystemBeanArchiveHandler - Handle archive file: /home/u142040/Desktop/temp/dw-weld-maven/target/dw-weld-maven-1.0-SNAPSHOT.jar
10:48:41.577 [main] DEBUG org.jboss.weld.Bootstrap - WELD-ENV-000024: Archive isolation enabled - creating multiple isolated bean archives if needed
10:48:41.618 [main] DEBUG org.jboss.weld.Configuration - WELD-001902: Configuration initialized: {}
10:48:41.642 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000124: Using 4 threads for bootstrap
10:48:41.649 [main] DEBUG org.jboss.weld.Bootstrap - Using instantiator: org.jboss.weld.bean.proxy.DefaultProxyInstantiator
10:48:41.649 [main] INFO org.jboss.weld.Bootstrap - WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
10:48:41.694 [main] WARN org.jboss.weld.Interceptor - WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
10:48:41.694 [main] WARN org.jboss.weld.Interceptor - WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
10:48:41.721 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%ApplicationContext
10:48:41.725 [main] DEBUG org.jboss.weld.Reflection - WELD-000601: interface javax.inject.Singleton is missing @Target. Weld will use this annotation, however this may make the application unportable.
10:48:41.728 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%SingletonContext
10:48:41.731 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%BoundSessionContext
10:48:41.732 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%BoundConversationContext
10:48:41.733 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%BoundRequestContext
10:48:41.733 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%RequestContext
10:48:41.735 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%DependentContext
10:48:41.736 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%HttpSessionContext
10:48:41.736 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%HttpSessionDestructionContext
10:48:41.737 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%HttpConversationContext
10:48:41.737 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: WELD%AbstractBuiltInBean%deployment%HttpRequestContext
10:48:41.754 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: Built-in Bean [javax.enterprise.inject.spi.BeanManager] with qualifiers [@Default]
10:48:41.755 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: Built-in Bean [org.jboss.weld.manager.BeanManagerImpl] with qualifiers [@Default]
10:48:41.792 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: Extension [class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider] with qualifiers [@Default]; jar:file:/home/u142040/Desktop/temp/dw-weld-maven/target/dw-weld-maven-1.0-SNAPSHOT.jar!/META-INF/services/javax.enterprise.inject.spi.Extension@2[org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider@39529185]
10:48:41.796 [main] INFO org.jboss.weld.Event - WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
10:48:41.801 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: Extension [class org.jboss.weld.environment.se.WeldSEBeanRegistrant] with qualifiers [@Default]; jar:file:/home/u142040/Desktop/temp/dw-weld-maven/target/dw-weld-maven-1.0-SNAPSHOT.jar!/META-INF/services/javax.enterprise.inject.spi.Extension@1[org.jboss.weld.environment.se.WeldSEBeanRegistrant@61862a7f]
10:48:41.801 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: Built-in Bean [javax.enterprise.inject.spi.BeanManager] with qualifiers [@Default]
10:48:41.802 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106: Bean: Built-in Bean [org.jboss.weld.manager.BeanManagerImpl] with qualifiers [@Default]
10:48:41.873 [weld-worker-4] INFO org.jboss.weld.Bootstrap - WELD-000119: Not generating any bean definitions from org.checkerframework.checker.formatter.FormatUtil$Conversion because of underlying class loading error: Type org.checkerframework.checker.formatter.qual.ConversionCategory not found. If this is unexpected, enable DEBUG logging to see the full error.
10:48:41.881 [weld-worker-4] DEBUG org.jboss.weld.Bootstrap - Catching
org.jboss.weld.resources.spi.ResourceLoadingException: java.lang.NoClassDefFoundError: Lorg/checkerframework/checker/formatter/qual/ConversionCategory;
at org.jboss.weld.environment.deployment.WeldResourceLoader.classForName(WeldResourceLoader.java:61)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadClass(AnnotatedTypeLoader.java:65)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:60)
at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:97)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:65)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:62)
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(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: Lorg/checkerframework/checker/formatter/qual/ConversionCategory;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.jboss.weld.environment.deployment.WeldResourceLoader.classForName(WeldResourceLoader.java:53)
... 11 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.checkerframework.checker.formatter.qual.ConversionCategory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 common frames omitted
10:48:41.905 [weld-worker-4] INFO org.jboss.weld.Bootstrap - WELD-000119: Not generating any bean definitions from ch.qos.logback.classic.gaffer.PropertyUtil$_upperCaseFirstLetter_closure1 because of underlying class loading error: Type org.codehaus.groovy.runtime.GeneratedClosure not found. If this is unexpected, enable DEBUG logging to see the full error.
10:48:41.907 [weld-worker-4] DEBUG org.jboss.weld.Bootstrap - Catching
org.jboss.weld.resources.spi.ResourceLoadingException: java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/GeneratedClosure
at org.jboss.weld.environment.deployment.WeldResourceLoader.classForName(WeldResourceLoader.java:61)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadClass(AnnotatedTypeLoader.java:65)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:60)
at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:97)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:65)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:62)
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(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/GeneratedClosure
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jboss.weld.environment.deployment.WeldResourceLoader.classForName(WeldResourceLoader.java:40)
... 11 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.GeneratedClosure
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 common frames omitted
10:48:42.306 [weld-worker-1] INFO org.jboss.weld.Bootstrap - WELD-000119: Not generating any bean definitions from jersey.repackaged.com.google.common.collect.AbstractMultimap$EntrySet because of underlying class loading error: Type [unknown] not found. If this is unexpected, enable DEBUG logging to see the full error.
10:48:42.306 [weld-worker-1] DEBUG org.jboss.weld.Bootstrap - Catching
org.jboss.weld.resources.spi.ResourceLoadingException: Error while loading class jersey.repackaged.com.google.common.collect.AbstractMultimap$EntrySet
at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:186)
at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:194)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:78)
at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:60)
at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:97)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:65)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:62)
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(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.GenericSignatureFormatError: Signature Parse error: expected '<' or ';' or '.', got '/'.
Remaining input: /repackaged/com/google/common/collect/AbstractMultimap$Entries;Ljava/util/Set<Ljava/util/Map$Entry<TK;TV;>;>;
at sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:124)
at sun.reflect.generics.parser.SignatureParser.parseSimpleClassTypeSignature(SignatureParser.java:367)
at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignatureSuffix(SignatureParser.java:378)
at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java:312)
at sun.reflect.generics.parser.SignatureParser.parseClassSignature(SignatureParser.java:213)
at sun.reflect.generics.parser.SignatureParser.parseClassSig(SignatureParser.java:156)
at sun.reflect.generics.repository.ClassRepository.parse(ClassRepository.java:57)
at sun.reflect.generics.repository.ClassRepository.parse(ClassRepository.java:41)
at sun.reflect.generics.repository.AbstractRepository.<init>(AbstractRepository.java:74)
at sun.reflect.generics.repository.GenericDeclRepository.<init>(GenericDeclRepository.java:49)
at sun.reflect.generics.repository.ClassRepository.<init>(ClassRepository.java:53)
at sun.reflect.generics.repository.ClassRepository.make(ClassRepository.java:70)
at java.lang.Class.getGenericInfo(Class.java:2548)
at java.lang.Class.getTypeParameters(Class.java:713)
at org.jboss.weld.util.Types.getCanonicalType(Types.java:143)
at org.jboss.weld.util.Types.getCanonicalType(Types.java:158)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.initTypeClosure(BackedAnnotatedType.java:73)
at org.jboss.weld.annotated.slim.backed.BackedAnnotated.<init>(BackedAnnotated.java:19)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.<init>(BackedAnnotatedType.java:60)
at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.of(BackedAnnotatedType.java:48)
at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:83)
at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:80)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2250)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2133)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2046)
at com.google.common.cache.LocalCache.get(LocalCache.java:3963)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3967)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4952)
at org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java:49)
at org.jboss.weld.util.cache.LoadingCacheUtils.getCastCacheValue(LoadingCacheUtils.java:74)
at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:175)
... 12 common frames omitted
10:48:42.347 [weld-worker-4] INFO org.jboss.weld.Bootstrap - WELD-000119: Not generating any bean definitions from org.glassfish.hk2.osgiresourcelocator.ServiceLoaderImpl because of underlying class loading error: Type org.osgi.framework.BundleListener not found. If this is unexpected, enable DEBUG logging to see the full error.
10:48:42.349 [weld-worker-4] DEBUG org.jboss.weld.Bootstrap - Catching
org.jboss.weld.resources.spi.ResourceLoadingException: java.lang.NoClassDefFoundError: org/osgi/framework/BundleListener
Так что в основном pom.xml
исходит из архетипа Dropwizard maven с дополнительными зависимостями Weld. Файл beans.xml пуст.
Запуская FatJAR, созданный плагином Maven Shade, я получаю много NoClassDefFounError
, Интересно, что приложение работает как с IDE для запуска, так и с плагином приложения Gradle (installDist). Таким образом, ошибка, похоже, связана с FatJAR (classpath?).
Какие-либо предложения?