java - 如何从不是使用 Maven 构建的 jar 中排除作为 Maven 依赖项的类?

标签 java maven javafx-2 javafx maven-3

当我阅读java web services : up and running一书时,我正在尝试构建一个简单的javafx应用程序来使用基于SOAP的Web服务(问题与 java web 服务无关),我正在使用: - 网 bean 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 简单构建并仅提供一个 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: the jar generated after the operation works without any problems, I'm just trying to get a perfect build result.

最佳答案

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

为 jar 选择版本号时,最好添加一个额外的字符串,以表明它是一个与原始网站略有不同的 jar。

关于java - 如何从不是使用 Maven 构建的 jar 中排除作为 Maven 依赖项的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15046710/

相关文章:

java - Hibernate指定的cfg.xml文件[/src/main/resources/hibernate.cfg.xml]不存在

java - Jenkins 无法识别 Java 1.6

Java泛型捕获错误 "? super capture#1 of ? super T"

java - 编译程序集:single error

java - 使用一个项目作为另一个项目的 Maven 依赖项

java - 结合 javafx 2 ListView 和 GridPane 功能

java - 两个 tableView 和一个使用 JavaFx 的选择

java - 如何使我的默认 JDK FX 启用?

java - 恢复应用程序后上下文为空

java - 成绩计算器程序