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

时间:2015-12-02 05:21:17

标签: java maven intellij-idea java-web-start jnlp

我在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进行编译,并使用dependensies进行编译。
  2. 编译,打包Web模块,将最近打包的web-start-swt-jar复制到webapp \ webstartFolder \?
  3. 是的我使用maven assemply插件,但它复制了没有依赖项的jar文件。

    谢谢!

    P.S。您可能建议使用一些插件来安装web-start工作吗?例如webstart-maven-plugin?请帮忙。

2 个答案:

答案 0 :(得分:1)

[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>

答案 1 :(得分:0)

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

别忘了通过<dependency managament>

设置depended 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文件夹中重复...