Dropwizard - 线程“main”中的异常java.lang.NoClassDefFoundError:com / google / common / collect / ImmutableMap $ Builder

时间:2016-12-08 06:24:54

标签: java maven dropwizard

我已经从maven原型创建了一个示例maven项目DropwizardApp - Group Id:io.dropwizard.archetypes ArtifactId:java-simple。下面是默认生成的两个类。

DropwizardAppApplication.java

package com.nagra.DropwizardApp;

import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

public class DropwizardAppApplication extends Application<DropwizardAppConfiguration> {

public static void main(final String[] args) throws Exception {
    new DropwizardAppApplication().run(args);
}

@Override
public String getName() {
    return "DropwizardApp";
}

@Override
public void initialize(final Bootstrap<DropwizardAppConfiguration> bootstrap) {
    // TODO: application initialization
}

@Override
public void run(final DropwizardAppConfiguration configuration,
                final Environment environment) {
    // TODO: implement application
}

}

和DropwizardAppConfiguration.java

package com.nagra.DropwizardApp;

import io.dropwizard.Configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.*;
import javax.validation.constraints.*;

public class DropwizardAppConfiguration extends Configuration {
// TODO: implement service configuration
}

并尝试运行DropwizardAppApplication但低于错误。

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap$Builder
at io.dropwizard.util.Duration.<clinit>(Duration.java:19)
at io.dropwizard.logging.LoggingUtil.<clinit>(LoggingUtil.java:14)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:38)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:34)
at io.dropwizard.Application.<init>(Application.java:24)
at com.nagra.DropwizardApp.DropwizardAppApplication.<init>(DropwizardAppApplication.java:7)
at com.nagra.DropwizardApp.DropwizardAppApplication.main(DropwizardAppApplication.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap$Builder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

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>com.nagra</groupId>
            <artifactId>DropwizardApp</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <packaging>jar</packaging>

            <name>DropwizardApp</name>

            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
                <dropwizard.version>1.0.5</dropwizard.version>
                <mainClass>com.nagra.DropwizardApp.DropwizardAppApplication</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>
                    <version>${dropwizard.version}</version>
                </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>2.6</version>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    <mainClass>${mainClass}</mainClass>
                                </manifest>
                            </archive>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.3</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.4</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.10.3</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>

            <reporting>
                <plugins>
                    <plugin>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                        <version>2.8.1</version>
                        <configuration>
                            <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                            <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.10.3</version>
                    </plugin>
                </plugins>
            </reporting>
        </project>

1 个答案:

答案 0 :(得分:0)

Prasad,尝试以下两个引导程序并运行应用程序(注意将此作为答案发布,因为这将不适合评论)

使用以下方式创建项目:

MergeHub.source[(Promise[String], String)]()

然后运行应用程序,生成的pom是

mvn archetype:generate -DgroupId=com.nagra   -DartifactId=DropwizardApp -Dname=DropwizardAppApplication -DarchetypeGroupId=io.dropwizard.archetypes -DarchetypeArtifactId=java-simple -DarchetypeVersion=1.1.0 -Dpackage=com.nagra.DropwizardApp

并启动应用程序。你可以查一次吗

<?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>com.nagra</groupId>                                                                                        
    <artifactId>DropwizardApp</artifactId>                                                                              
    <version>1.0-SNAPSHOT</version>                                                                                     
    <packaging>jar</packaging>                                                                                          

    <name>DropwizardAppApplication</name>                                                                               

    <properties>                                                                                                        
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>                                              
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>                                      
        <dropwizard.version>1.0.5</dropwizard.version>                                                                  
        <mainClass>com.nagra.DropwizardApp.DropwizardAppApplicationApplication</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>                                                                                                   
    </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>2.6</version>                                                                                  
                <configuration>                                                                                         
                    <archive>                                                                                           
                        <manifest>                                                                                      
                            <addClasspath>true</addClasspath>                                                           
                            <mainClass>${mainClass}</mainClass>                                                         
                        </manifest>                                                                                     
                    </archive>                                                                                          
                </configuration>                                                                                        
            </plugin>                                                                                                   
            <plugin>                                                                                                    
                <artifactId>maven-compiler-plugin</artifactId>                                                          
                <version>3.3</version>                                                                                  
                <configuration>                                                                                         
                    <source>1.8</source>                                                                                
                    <target>1.8</target>                                                                                
                </configuration>                                                                                        
            </plugin>                                                                                                   
            <plugin>                                                                                                    
                <artifactId>maven-source-plugin</artifactId>                                                            
                <version>2.4</version>                                                                                  
                <executions>                                                                                            
                    <execution>                                                                                         
                        <id>attach-sources</id>                                                                         
                        <goals>                                                                                         
                            <goal>jar</goal>                                                                            
                        </goals>                                                                                        
                    </execution>                                                                                        
                </executions>                                                                                           
            </plugin>                                                                                                   
            <plugin>                                                                                                    
                <artifactId>maven-javadoc-plugin</artifactId>                                                           
                <version>2.10.3</version>                                                                               
                <executions>                                                                                            
                    <execution>                                                                                         
                        <id>attach-javadocs</id>                                                                        
                        <goals>                                                                                         
                            <goal>jar</goal>                                                                            
                        </goals>                                                                                        
                    </execution>                                                                                        
                </executions>                                                                                           
            </plugin>                                                                                                   
        </plugins>                                                                                                      
    </build>                                                                                                            

    <reporting>                                                                                                         
        <plugins>                                                                                                       
            <plugin>                                                                                                    
                <artifactId>maven-project-info-reports-plugin</artifactId>                                              
                <version>2.8.1</version>                                                                                
                <configuration>                                                                                         
                    <dependencyLocationsEnabled>false</dependencyLocationsEnabled>                                      
                    <dependencyDetailsEnabled>false</dependencyDetailsEnabled>                                          
                </configuration>                                                                                        
            </plugin>                                                                                                   
            <plugin>                                                                                                    
                <artifactId>maven-javadoc-plugin</artifactId>                                                           
                <version>2.10.3</version>                                                                               
            </plugin>                                                                                                   
        </plugins>                                                                                                      
    </reporting>                                                                                                        
</project>