简体   繁体   English

在正确目录下生成的jar中无法解析POM中指定的依赖项

[英]Dependencies specified in POM not resolved in the generated jar in correct directory

I want to create a JAR file of my maven application. 我想创建我的Maven应用程序的JAR文件。 So to bundle the dependencies I have used the maven-assembly-plugin. 因此,为了捆绑依赖项,我使用了maven-assembly-plugin。 But I want that the dependencies should go the lib/ folder and not anywhere else. 但是我希望依赖项应该放在lib /文件夹中,而不是其他任何地方。 My current pom.xml plugin tag is 我当前的pom.xml插件标签是

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Please suggest. 请提出建议。 Also is it possible to achieve the same with maven jar plugin. 使用maven jar插件也可以实现相同的目的。

After the above changes in POM The dependencies get generated in the jar which is generated with suffix 'jar-with-dependencies'. 在POM中进行上述更改之后,将在后缀为“ jar-with-dependencies”的jar中生成依赖项。 But the dependent jars are scattered I want all those dependent jars to be part of one folder lib similart to WEB-INF/lib for war files. 但是相关的jar分散了,我希望所有这些相关的jar都属于一个类似于战争文件WEB-INF / lib的文件夹lib。 How do I achieve this? 我该如何实现?

You can achieve this with a custom assembly descriptor (a xml file) like this: 您可以使用自定义程序集描述符(xml文件)来实现此目的,如下所示:

<assembly
   xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

  <id>dist</id>

  <formats>
    <format>dir</format>
  </formats>

  <fileSets>
    <fileSet>
      <directory>target</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>your-application.jar</include>
      </includes>
    </fileSet>
  </fileSets>

  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>

</assembly>

You have to point to the assembly descriptor in your maven assembly plugin configuration: 您必须在maven程序集插件配置中指向程序集描述符:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.4.1</version>
  <configuration>
    <descriptors>
      <descriptor>assemble.xml</descriptor>
    </descriptors>
  </configuration>
  ...
</plugin>

Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM