有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Dropwizard中添加依赖项

我正在构建一个新的微服务,在这里我必须使用第三方客户端库来解决地理定位问题。 我已经在pom文件中添加了该服务的依赖项

<groupId>abc.xyz.abc.geo</groupId>
           <artifactId>MyGeoLocation</artifactId>
           <version>1.5.0</version>
       </dependency>

但是,如何在新的服务/应用程序中注入此服务的依赖关系


共 (1) 个答案

  1. # 1 楼答案

    根据dropwizard docs你应该生成一个fat-jar。其中包括一个如何使用maven-shade

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <configuration>
            <createDependencyReducedPom>true</createDependencyReducedPom>
            <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>
                <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.example.helloworld.HelloWorldApplication</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    记住用项目的主类更改com.example.helloworld...