如何在 Maven Idea 的 webapp\myfolder 中复制 jar-with-dependencies

How to copy jar-with-dependencies in my webapp\myfolder in maven Idea

我在 Idea 中有一个带有两个模块的 maven 项目:1)web 和 2)web-start-swt-jar。

web-start-swt-jar pom.xml 配置为打包依赖项。

我的项目是这样的:

[root]
  - web-start-swt-jar   pom.xml (packaging jar)
  - web  pom.xml (packaging war)
 pom.xml (packaging pom)

是否可以执行我想要的这些步骤:

  1. 编译,打包依赖web-start-swt-jar。
  2. 编译、打包web模块,复制最近打包的web-start-swt-jar到webapp\webstartFolder\ ?

是的,我使用 maven assemply 插件,但它复制了没有依赖项的 jar 文件。

谢谢!

p.s。也许你建议使用一些插件来舒适地使用 web-start 工作?例如webstart-maven-插件?请帮忙

似乎找到了答案:在 prepare-package 阶段使用 maven-shade-plugin 打包带有依赖项的 jar 和 maven-dependency-plugin 复制到自定义文件夹。

不要忘记通过<dependency managament>

设置依赖jar的版本
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>



<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>my.group</groupId>
                                    <artifactId>webstart-swt-jar</artifactId>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>
                                        ${project.build.directory}/${project.build.finalName}/SomeFolderHere
                                    </outputDirectory>
                                    <destFileName>(optional rename..)webstart-swt-jar.jar</destFileName>
                                </artifactItem>
                            </artifactItems>

                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

已添加: 但是,如果我不将 webstart-swt-jar 设置为依赖项,构建将失败并出现错误 "webstart-swt-jar not found"。这不好,因为工件在 WEB-INF\lib 和我的 \custom 文件夹中重复...

[root]
  - web-start-swt-jar   pom.xml (packaging jar)
  - web  pom.xml (packaging war)
 pom.xml (packaging pom)

尝试添加这个:web pom.xml

<dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>web-start-swt-jar</artifactId>
</dependency>

 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                 <groupId>${project.groupId}</groupId>
                <artifactId>web-start-swt-jar</artifactId>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                  <!-- outputDirectory not sure. to test-->
                  <outputDirectory>${basedir}/src/main/webapp/webstartFolder</outputDirectory>
                  <destFileName>web-start-swt-jar</destFileName>
                </artifactItem>
              </artifactItems> 
              <overWriteReleases>true</overWriteReleases>
              <overWriteSnapshots>true</overWriteSnapshots>
            </configuration>
          </execution>
        </executions>
      </plugin>