Pliki .java i javadoc jak upchnąć je do jara za pomocą Mavena

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>
<resources>
<resource>
<directory>src/main/java/</directory>
</resource>
</resources>
</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>
<reporting>
<outputDirectory>${basedir}/src/main/resources</outputDirectory>
</reporting>
</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
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'javadoc'.
[INFO] -------------------------------------------------------------------------
---
[INFO] Building example
[INFO] task-segment: [clean, compile]
[INFO] -------------------------------------------------------------------------
---
[INFO] [clean:clean]
[INFO] Deleting directory >\target
[INFO] Deleting directory >\target\classes
[INFO] Deleting directory >\target\test-classes
[INFO] Deleting directory >\src\main\resources
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 13 source files to >\target\classes
[INFO] -------------------------------------------------------------------------
---
[INFO] Building example
[INFO] task-segment: [javadoc:javadoc] (aggregator-style)
[INFO] -------------------------------------------------------------------------
---
[INFO] Preparing javadoc:javadoc
[INFO] -------------------------------------------------------------------------
---
[INFO] Building example
[INFO] -------------------------------------------------------------------------
---
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus
.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] **************************************************************
[INFO] Starting Jakarta Velocity v1.4
[INFO] RuntimeInstance initializing.
[INFO] Default Properties File: org\apache\velocity\runtime\defaults\velocity.pr
operties
[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.
resource.ResourceManagerImpl)
[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLo
aderResourceLoader
[INFO] ClasspathResourceLoader : initialization starting.
[INFO] ClasspathResourceLoader : initialization complete.
[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.
ResourceCacheImpl)
[INFO] Default ResourceManager initialization complete.
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[INFO] Created: 20 parsers.
[INFO] Velocimacro : initialization starting.
[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm
[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any
resource loader.
[INFO] Velocimacro : error using VM library template VM_global_library.vm : org
.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'V
M_global_library.vm'
[INFO] Velocimacro : VM library template macro registration complete.
[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates

[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT
replace previous VM definitions
[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be glob
al in scope if allowed.
[INFO] Velocimacro : initialization complete.
[INFO] Velocity successfully started.
[INFO] [javadoc:javadoc]
Loading source file >/src/main/java/Main.java...
Loading source files for package utils...
Loading source files for package zadanie1...
Loading source files for package zadanie2...
Constructing Javadoc information...
Standard Doclet version 1.5.0_12
Building tree for all the packages and classes...
Generating >/src/main/resources/apidocs\Main.html...
Generating >/src/main/resources/apidocs\utils/\Keyboard
Reader.html...
Generating >/src/main/resources/apidocs\zadanie1/\App.h
tml...
Generating >/src/main/resources/apidocs\zadanie1/\Ciag.
html...
Generating >/src/main/resources/apidocs\zadanie1/\Ciag2
.html...
Generating >/src/main/resources/apidocs\zadanie1/\Wyraz
enie.html...
Generating >/src/main/resources/apidocs\zadanie2/\App.h
tml...
Generating >/src/main/resources/apidocs\zadanie2/\Eleme
nt.html...
Generating >/src/main/resources/apidocs\zadanie2/\Eleme
ntInteger.html...
Generating >/src/main/resources/apidocs\zadanie2/\Przes
uwalny.html...
Generating >/src/main/resources/apidocs\zadanie2/\Sorto
wanie.html...
Generating >/src/main/resources/apidocs\zadanie2/\Sorto
wanieProste.html...
Generating >/src/main/resources/apidocs\overview-frame.
html...
Generating >/src/main/resources/apidocs\package-frame.h
tml...
Generating >/src/main/resources/apidocs\package-summary
.html...
Generating >/src/main/resources/apidocs\package-tree.ht
ml...
Generating >/src/main/resources/apidocs\utils/\package-
frame.html...
Generating >/src/main/resources/apidocs\utils/\package-
summary.html...
Generating >/src/main/resources/apidocs\utils/\package-
tree.html...
Generating >/src/main/resources/apidocs\zadanie1/\packa
ge-frame.html...
Generating >/src/main/resources/apidocs\zadanie1/\packa
ge-summary.html...
Generating >/src/main/resources/apidocs\zadanie1/\packa
ge-tree.html...
Generating >/src/main/resources/apidocs\zadanie2/\packa
ge-frame.html...
Generating >/src/main/resources/apidocs\zadanie2/\packa
ge-summary.html...
Generating >/src/main/resources/apidocs\zadanie2/\packa
ge-tree.html...
Generating >/src/main/resources/apidocs\constant-values
.html...
Generating >/src/main/resources/apidocs\class-use\Main.
html...
Generating >/src/main/resources/apidocs\utils/\class-us
e\KeyboardReader.html...
Generating >/src/main/resources/apidocs\zadanie1/\class
-use\Wyrazenie.html...
Generating >/src/main/resources/apidocs\zadanie1/\class
-use\Ciag2.html...
Generating >/src/main/resources/apidocs\zadanie1/\class
-use\Ciag.html...
Generating >/src/main/resources/apidocs\zadanie1/\class
-use\App.html...
Generating >/src/main/resources/apidocs\zadanie2/\class
-use\SortowanieProste.html...
Generating >/src/main/resources/apidocs\zadanie2/\class
-use\Sortowanie.html...
Generating >/src/main/resources/apidocs\zadanie2/\class
-use\Przesuwalny.html...
Generating >/src/main/resources/apidocs\zadanie2/\class
-use\ElementInteger.html...
Generating >/src/main/resources/apidocs\zadanie2/\class
-use\Element.html...
Generating >/src/main/resources/apidocs\zadanie2/\class
-use\App.html...
Generating >/src/main/resources/apidocs\package-use.htm
l...
Generating >/src/main/resources/apidocs\utils/\package-
use.html...
Generating >/src/main/resources/apidocs\zadanie1/\packa
ge-use.html...
Generating >/src/main/resources/apidocs\zadanie2/\packa
ge-use.html...
Building index for all the packages and classes...
Generating >/src/main/resources/apidocs\overview-tree.h
tml...
Generating >/src/main/resources/apidocs\index-all.html.
..
Generating >/src/main/resources/apidocs\deprecated-list
.html...
Building index for all classes...
Generating >/src/main/resources/apidocs\allclasses-fram
e.html...
Generating >/src/main/resources/apidocs\allclasses-nofr
ame.html...
Generating >/src/main/resources/apidocs\index.html...
Generating >/src/main/resources/apidocs\overview-summar
y.html...
Generating >/src/main/resources/apidocs\help-doc.html..
.
Generating >/src/main/resources/apidocs\stylesheet.css.
..
[INFO] -------------------------------------------------------------------------
---
[INFO] Building example
[INFO] task-segment: [jar:jar]
[INFO] -------------------------------------------------------------------------
---
[INFO] [jar:jar]
[INFO] Building jar: >\target\main.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Sun Jan 06 01:26:15 CET 2008
[INFO] Final Memory: 8M/17M
[INFO] ------------------------------------------------------------------------

>

i udać się na spoczynek…

Napisz odpowiedź

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax