Ciekawe pytanie, prawda? Niby odpowiedź jest banalnie prosta, ale wymaga od programisty chwili walki. Okazuje się, że nie jest to wbrew pozorom takie proste. Prawidłowe rozwiązanie wymaga skonfigurowania dwóch rzeczy. Po pierwsze należy określić dodatkowe katalogi z zasobami:

Listing 1. Dodatkowe zasoby

<build><br></br> <resources><br></br>  <resource><br></br>   <directory>src/main/java/</directory><br></br>  </resource><br></br> </resources><br></br></build>

W ten sposób dodamy pliki java. Po drugie należy jeszcze dodać javadoc. Konfiguracja jest znacznie bardziej upierdliwa, ponieważ odbywa się w dwóch miejscach. Pierwszym z nich jest javadoc plugin. Opisywałem to już kiedyś. Drugim i nie tak oczywistym jest odpowiednie skonfigurowanie sekcji reporting:

Listing 2. Wbrew pozorom sekcja reporting jest bardzo ważna

<project><br></br> <reporting><br></br>  <outputDirectory>${basedir}/src/main/resources</outputDirectory><br></br> </reporting><br></br></project>

No i na tym koniec. Wystarczy wywołać tylko mavena z odpowiednimi opcjami:

Listing 3. Wielki Finał – uruchamiamy

>mvn clean compile javadoc:javadoc jar:jar<br></br>[INFO] Scanning for projects...<br></br>[INFO] Searching repository for plugin with prefix: 'javadoc'.<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] Building example<br></br>[INFO]    task-segment: [clean, compile]<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] [clean:clean]<br></br>[INFO] Deleting directory >\target<br></br>[INFO] Deleting directory >\target\classes<br></br>[INFO] Deleting directory >\target\test-classes<br></br>[INFO] Deleting directory >\src\main\resources<br></br>[INFO] [resources:resources]<br></br>[INFO] Using default encoding to copy filtered resources.<br></br>[INFO] [compiler:compile]<br></br>[INFO] Compiling 13 source files to >\target\classes<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] Building example<br></br>[INFO]    task-segment: [javadoc:javadoc] (aggregator-style)<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] Preparing javadoc:javadoc<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] Building example<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] No goals needed for project - skipping<br></br>[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus<br></br>.velocity.ContextClassLoaderResourceLoader'.<br></br>[INFO] Setting property: velocimacro.messages.on => 'false'.<br></br>[INFO] Setting property: resource.loader => 'classpath'.<br></br>[INFO] Setting property: resource.manager.logwhenfound => 'false'.<br></br>[INFO] **************************************************************<br></br>[INFO] Starting Jakarta Velocity v1.4<br></br>[INFO] RuntimeInstance initializing.<br></br>[INFO] Default Properties File: org\apache\velocity\runtime\defaults\velocity.pr<br></br>operties<br></br>[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.<br></br>resource.ResourceManagerImpl)<br></br>[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLo<br></br>aderResourceLoader<br></br>[INFO] ClasspathResourceLoader : initialization starting.<br></br>[INFO] ClasspathResourceLoader : initialization complete.<br></br>[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.<br></br>ResourceCacheImpl)<br></br>[INFO] Default ResourceManager initialization complete.<br></br>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal<br></br>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro<br></br>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse<br></br>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include<br></br>[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach<br></br>[INFO] Created: 20 parsers.<br></br>[INFO] Velocimacro : initialization starting.<br></br>[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm<br></br>[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any<br></br>resource loader.<br></br>[INFO] Velocimacro : error using  VM library template VM_global_library.vm : org<br></br>.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'V<br></br>M_global_library.vm'<br></br>[INFO] Velocimacro :  VM library template macro registration complete.<br></br>[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates<br></br><br></br>[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT<br></br>replace previous VM definitions<br></br>[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be  glob<br></br>al in scope if allowed.<br></br>[INFO] Velocimacro : initialization complete.<br></br>[INFO] Velocity successfully started.<br></br>[INFO] [javadoc:javadoc]<br></br>Loading source file >/src/main/java/Main.java...<br></br>Loading source files for package utils...<br></br>Loading source files for package zadanie1...<br></br>Loading source files for package zadanie2...<br></br>Constructing Javadoc information...<br></br>Standard Doclet version 1.5.0_12<br></br>Building tree for all the packages and classes...<br></br>Generating >/src/main/resources/apidocs\Main.html...<br></br>Generating >/src/main/resources/apidocs\utils/\Keyboard<br></br>Reader.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\App.h<br></br>tml...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\Ciag.<br></br>html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\Ciag2<br></br>.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\Wyraz<br></br>enie.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\App.h<br></br>tml...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\Eleme<br></br>nt.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\Eleme<br></br>ntInteger.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\Przes<br></br>uwalny.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\Sorto<br></br>wanie.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\Sorto<br></br>wanieProste.html...<br></br>Generating >/src/main/resources/apidocs\overview-frame.<br></br>html...<br></br>Generating >/src/main/resources/apidocs\package-frame.h<br></br>tml...<br></br>Generating >/src/main/resources/apidocs\package-summary<br></br>.html...<br></br>Generating >/src/main/resources/apidocs\package-tree.ht<br></br>ml...<br></br>Generating >/src/main/resources/apidocs\utils/\package-<br></br>frame.html...<br></br>Generating >/src/main/resources/apidocs\utils/\package-<br></br>summary.html...<br></br>Generating >/src/main/resources/apidocs\utils/\package-<br></br>tree.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\packa<br></br>ge-frame.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\packa<br></br>ge-summary.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\packa<br></br>ge-tree.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\packa<br></br>ge-frame.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\packa<br></br>ge-summary.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\packa<br></br>ge-tree.html...<br></br>Generating >/src/main/resources/apidocs\constant-values<br></br>.html...<br></br>Generating >/src/main/resources/apidocs\class-use\Main.<br></br>html...<br></br>Generating >/src/main/resources/apidocs\utils/\class-us<br></br>e\KeyboardReader.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\class<br></br>-use\Wyrazenie.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\class<br></br>-use\Ciag2.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\class<br></br>-use\Ciag.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\class<br></br>-use\App.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\class<br></br>-use\SortowanieProste.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\class<br></br>-use\Sortowanie.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\class<br></br>-use\Przesuwalny.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\class<br></br>-use\ElementInteger.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\class<br></br>-use\Element.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\class<br></br>-use\App.html...<br></br>Generating >/src/main/resources/apidocs\package-use.htm<br></br>l...<br></br>Generating >/src/main/resources/apidocs\utils/\package-<br></br>use.html...<br></br>Generating >/src/main/resources/apidocs\zadanie1/\packa<br></br>ge-use.html...<br></br>Generating >/src/main/resources/apidocs\zadanie2/\packa<br></br>ge-use.html...<br></br>Building index for all the packages and classes...<br></br>Generating >/src/main/resources/apidocs\overview-tree.h<br></br>tml...<br></br>Generating >/src/main/resources/apidocs\index-all.html.<br></br>..<br></br>Generating >/src/main/resources/apidocs\deprecated-list<br></br>.html...<br></br>Building index for all classes...<br></br>Generating >/src/main/resources/apidocs\allclasses-fram<br></br>e.html...<br></br>Generating >/src/main/resources/apidocs\allclasses-nofr<br></br>ame.html...<br></br>Generating >/src/main/resources/apidocs\index.html...<br></br>Generating >/src/main/resources/apidocs\overview-summar<br></br>y.html...<br></br>Generating >/src/main/resources/apidocs\help-doc.html..<br></br>.<br></br>Generating >/src/main/resources/apidocs\stylesheet.css.<br></br>..<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] Building example<br></br>[INFO]    task-segment: [jar:jar]<br></br>[INFO] -------------------------------------------------------------------------<br></br>---<br></br>[INFO] [jar:jar]<br></br>[INFO] Building jar: >\target\main.jar<br></br>[INFO] ------------------------------------------------------------------------<br></br>[INFO] BUILD SUCCESSFUL<br></br>[INFO] ------------------------------------------------------------------------<br></br>[INFO] Total time: 7 seconds<br></br>[INFO] Finished at: Sun Jan 06 01:26:15 CET 2008<br></br>[INFO] Final Memory: 8M/17M<br></br>[INFO] ------------------------------------------------------------------------<br></br><br></br>>

i udać się na spoczynek…