2016-09-20 145 views
0

我已經編寫了自己的java doclet,並希望將其打包到單個jar文件中以便稍後使用它。使用maven打包自定義javadoc doclet

我目前使用這些設置Maven來生成它:

<build> 
    <finalName>Doclet</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.3.1</version> 
      <configuration> 
       <archive> 
       <manifest> 
        <addClasspath>true</addClasspath> 
        <mainClass>de.test.tools.doclet.Doclet</mainClass> 
       </manifest> 
       </archive> 
      </configuration> 
     </plugin> 

     <!-- Maven Assembly Plugin --> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>make-my-jar-with-dependencies</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 

       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <mainClass>de.test.tools.doclet.Doclet</mainClass> 
        </manifest> 
       </archive> 

       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 

      </configuration> 
     </plugin> 
    </plugins> 
</build> 

問題:
一切適當包裝放進瓶子裏,但我的消息來源丟失。
如果我試圖做一個簡單的mvn package它告訴我,太陽包不存在。

error: package com.sun.javadoc does not exist

我想最後一部分的背後是爲什麼我無法找到我的消息來源罐子裏,因此我的問題是我怎麼能告訴行家忽略這些進口的主要原因。

+0

請參閱此[鏈接](http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-source-inclusion-simple.html)。 –

回答

0

問題是,maven找不到包com.sun.javadoc它位於java安裝目錄的/ lib文件夾中的tools.jar中。

Eclipse能夠執行它,因爲我將它添加到classpath中,但maven不知道他可以從哪裏獲取資源。因此,添加以下系統依賴解決了這個問題對我來說:

<dependency> 
    <scope>system</scope> 
    <groupId>com.sun</groupId> 
    <artifactId>tools</artifactId> 
    <version>YOUR_JAVA_VERSION</version> 
    <systemPath>${java.home}/../lib/tools.jar</systemPath> 
</dependency> 

替換爲您版本的版本,並確保Java的家在您的環境知。

注意:此依賴關係不適用於MacOS。請參閱:JDK tools.jar as maven dependency - 摘要:使用每個操作系統的配置文件能夠指定正確的路徑。

我只需要支持Linux + Windows,因此它對我來說是最好的解決方案。