如何从不使用maven构建的jar中将类作为maven依赖项排除?

时间:2013-02-23 22:59:21

标签: java maven javafx-2 javafx maven-3

我正在尝试构建一个简单的 javafx 应用程序,以便在我阅读 java web services时使用基于SOAP的Web服务:启动并运行本书(问题不是关于java web服务),我正在使用:   - netbeans 7.3   - javafx-maven-plugin 1.5用于管理依赖项(我正在使用maven 3.0.4)   - tiwulfx 1.1与POJO互动

这是我的 POM 文件:

<groupId>org.tarrsalah</groupId>
  <artifactId>teams-client</artifactId>
  <version>0.0.99</version>
  <packaging>jar</packaging>

  <name>teams-client</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <netbeans.hint.license>apache20</netbeans.hint.license>
  </properties> 

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
      <scope>compile</scope>
    </dependency
    >
    <dependency>      
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.8</version>
    </dependency>

    <dependency>
      <groupId>com.panemenu</groupId>
      <artifactId>tiwulfx</artifactId>
      <scope>compile</scope>
      <version>1.1</version>
      <type>jar</type>    
    </dependency>

    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <scope>compile</scope>
      <version>1.8.3</version>
    </dependency>
  </dependencies>     

  <build>
    <plugins>
      <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
            <phase>generate-sources</phase>
          </execution>
        </executions>
        <configuration>         
          <wsdlUrls>
            <wsdlUrl>http://localhost:8080/teams?wsdl</wsdlUrl>
          </wsdlUrls>
          <packageName>org.tarrsalah.teams.client.generated</packageName>          >
        </configuration>
      </plugin>            

      <plugin>
        <groupId>com.zenjava</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version> 1.5 </version>
        <configuration>         
          <mainClass>org.tarrsalah.teams.client.app.App</mainClass>
          <jarFileName>teams-client.jar</jarFileName>
          <vendor>tarrsalah</vendor>                                                           
        </configuration>                                    
      </plugin>
    </plugins>
  </build>
</project>

我下载了tiwulfx jar文件,并在 POM 文件中添加了所有依赖项,并将其安装在我的maven本地存储库中(该项目使用netbeans / ant simple build并提供只是一个jar文件)。

我正在尝试构建一个自包含的可运行jar,当我运行时:      mvn clean编译jfx:build-jar

我收到此构建错误消息:

[INFO] Java home is: /home/tarrsalah/local/jdk1.7.0_15/jre
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.445s
[INFO] Finished at: Sat Feb 23 23:39:31 CET 2013
[INFO] Final Memory: 21M/350M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.zenjava:javafx-maven-plugin:1.5:build-jar (default-cli) on project teams-client: Invocation of JavaFX method 'packageAsJar' failed with an error. It's possible this plugin is not compatible with the version of JavaFX you are using. InvocationTargetException: Error: Failed to create jar file teams-client-0.0.99-jfx.jar: duplicate entry: com/javafx/main/Main.class -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

似乎javafx类已经包含在tiwulfx jar文件中,并且在打包阶段与javafx-maven-plugin导入的JDK中的javafx类(我使用的是1.7u15)发生冲突。

这就是树依赖关系的样子:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building teams-client 0.0.99
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ teams-client ---
[INFO] org.tarrsalah:teams-client:jar:0.0.99
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.apache.poi:poi:jar:3.8:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.5:compile
[INFO] +- com.panemenu:tiwulfx:jar:1.1:compile
[INFO] \- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO]    \- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for duplicate)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.137s
[INFO] Finished at: Sun Feb 24 00:21:34 CET 2013
[INFO] Final Memory: 10M/163M
[INFO] ------------------------------------------------------------------------

我的问题是:如何在打包阶段从tiwulfx中排除javafx类(包)?这可能是一个微不足道的问题,因为我是maven生态系统的新手。

  

P.S:操作后生成的jar没有任何问题,我只是想获得完美的构建结果。

2 个答案:

答案 0 :(得分:3)

由于您需要手动将tiwulfx jar添加到Maven仓库中(它不是由Maven构建的,并且它不是托管在任何地方的Maven仓库中),您也可以先手动重新打包。只需在zip编辑器中打开jar并删除com/javafx文件夹即可。然后运行通常的install:install-file目标。

在为jar选择版本号时,最好添加一个额外的字符串以使其清楚,它与原始网站上的jar略有不同。

答案 1 :(得分:2)

现在可以在Maven中使用TiwulFX。

<dependency>
    <groupId>com.panemu</groupId>
    <artifactId>tiwulfx</artifactId>
    <version>1.1</version>
</dependency>

感谢。