簡體   English   中英

如何從不是用Maven構建的jar中將類作為Maven依賴項排除在外?

[英]How to exclude a class as a maven dependency from a jar that is not built with maven?

我正在嘗試構建一個簡單的javafx應用程序,以在閱讀Java Web服務時使用基於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簡單構建,僅提供jar文件)。

我在運行時嘗試構建自包含的可運行jar:mvn clean compile 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

看來tiwulfx jar文件中已經包含javafx類,並且與在打包階段由javafx-maven-plugin導入的JDK(我正在使用1.7u15)中的javafx類產生沖突。

樹的依賴關系如下所示:

[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生態系統的新手。

PS:操作后生成的jar可以正常運行,我只是想獲得完美的構建結果。

由於您需要tiwulfxtiwulfx jar添加到您的Maven tiwulfx (它不是Maven構建的,也不是在任何地方的Maven tiwulfx托管的),因此您最好先手工重新打包。 只需在zip編輯器中打開jar並刪除com/javafx文件夾即可。 然后運行通常的install:install-file目標。

在選擇罐子的版本號時,最好添加一個額外的字符串,以使其與原始網站上的罐子有所不同。

現在TiwulFX在Maven中可用。

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

謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM