# maven-javadoc-plugin: package does not exist



## harrysun (5. Dez 2010)

Hallo Leute,

ich möchte die Warnungen von JavaDOC korrigieren -- genauer. Ich würde gerene in der generierten JavaDOC Dokumentation für alle externen Pakete ein Link auf die entsprechende Dokumentation erhalten.

In diesem Problemfall/Warnungen handelt es sich um http://www.slf4j.org/apidocs/package-list die anscheinend nicht berücksichtigt wird ?

```
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building exercise 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ exercise-1-1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ exercise-1-1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ exercise-1-1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/user/workspace/exercise/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ exercise-1-1 ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ exercise-1-1 ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ exercise-1-1 ---
[INFO] Building jar: /home/user/workspace/exercise/target/exercise-1-1-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-shade-plugin:1.4:shade (default) @ exercise-1-1 ---
[INFO] Including org.slf4j:slf4j-log4j12:jar:1.6.1 in the shaded jar.
[INFO] Including org.slf4j:slf4j-api:jar:1.6.1 in the shaded jar.
[INFO] Including log4j:log4j:jar:1.2.16 in the shaded jar.
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /home/user/workspace/exercise/target/exercise-1-1-0.0.1-SNAPSHOT.jar with /home/user/workspace/exercise/target/exercise-1-1-0.0.1-SNAPSHOT-shaded.jar
[INFO] 
[INFO] --- sonar-maven3-plugin:2.4.1:sonar (sonar) @ exercise-1-1 ---
[INFO]  Database dialect class org.sonar.jpa.dialect.Derby
[INFO]  -------------  Analyzing exercise
[INFO]  Selected quality profile : [name=Sonar way with Findbugs,language=java]
[INFO]  Configure maven plugins...
[INFO]  Sensor JavaSourceImporter...
[INFO]  Sensor JavaSourceImporter done: 113 ms
[INFO]  Sensor AsynchronousMeasuresSensor...
[INFO]  Sensor AsynchronousMeasuresSensor done: 100 ms
[INFO]  Sensor SquidSensor...
[INFO]  Java AST scan...
[INFO]  Java AST scan done: 156 ms
[INFO]  Java bytecode scan...
[INFO]  Java bytecode scan done: 37 ms
[INFO]  Squid extraction...
[INFO]  Package design analysis...
[INFO]  Package design analysis done: 6 ms
[INFO]  Squid extraction done: 115 ms
[INFO]  Sensor SquidSensor done: 345 ms
[INFO]  Sensor FindbugsSensor...
[INFO]  Execute Findbugs 1.3.9...
[INFO]  Findbugs output report: /home/user/workspace/exercise/target/sonar/findbugs-result.xml
[INFO]  Execute Findbugs 1.3.9 done: 2217 ms
[INFO]  Sensor FindbugsSensor done: 2279 ms
[INFO]  Execute maven plugin cobertura-maven-plugin...
[INFO]  Execute org.codehaus.mojo:cobertura-maven-plugin:2.4:cobertura...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building exercise 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> cobertura-maven-plugin:2.4:cobertura (default-cli) @ exercise-1-1 >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ exercise-1-1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ exercise-1-1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- cobertura-maven-plugin:2.4:instrument (default-cli) @ exercise-1-1 ---
[INFO] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 3 classes.
Instrumenting 3 files to /home/user/workspace/exercise/target/generated-classes/cobertura
Cobertura: Saved information on 3 classes.
Instrument time: 67ms

[INFO] Instrumentation was successful.
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ exercise-1-1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/user/workspace/exercise/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ exercise-1-1 ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ exercise-1-1 ---
[INFO] No tests to run.
[INFO] 
[INFO] <<< cobertura-maven-plugin:2.4:cobertura (default-cli) @ exercise-1-1 <<<
[INFO] 
[INFO] --- cobertura-maven-plugin:2.4:cobertura (default-cli) @ exercise-1-1 ---
[INFO] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 3 classes.
Report time: 85ms

[INFO] Cobertura Report generation was successful.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.660s
[INFO] Finished at: Sun Dec 05 14:05:44 CET 2010
[INFO] Final Memory: 17M/218M
[INFO] ------------------------------------------------------------------------
[INFO]  Execute org.codehaus.mojo:cobertura-maven-plugin:2.4:cobertura done: 874 ms
[INFO]  Execute maven plugin cobertura-maven-plugin done: 874 ms
[INFO]  Sensor CoberturaSensor...
[INFO]  parsing /home/user/workspace/exercise/target/site/cobertura/coverage.xml
[INFO]  Sensor CoberturaSensor done: 30 ms
[INFO]  Sensor CpdSensor...
[INFO]  Sensor CpdSensor done: 27 ms
[INFO]  Sensor CheckstyleSensor...
[INFO]  Execute Checkstyle 5.1...
[INFO]  Checkstyle configuration: /home/user/workspace/exercise/target/sonar/checkstyle.xml
[INFO]  Execute Checkstyle 5.1 done: 405 ms
[INFO]  Sensor CheckstyleSensor done: 406 ms
[INFO]  Sensor PmdSensor...
[INFO]  Execute PMD 4.2.5...
[INFO]  PMD configuration: /home/user/workspace/exercise/target/sonar/pmd.xml
[INFO]  PMD output report: /home/user/workspace/exercise/target/sonar/pmd-result.xml
[INFO]  Execute PMD 4.2.5 done: 932 ms
[INFO]  Sensor PmdSensor done: 934 ms
[INFO]  Sensor ProfileSensor...
[INFO]  Sensor ProfileSensor done: 24 ms
[INFO]  Sensor ProjectLinksSensor...
[INFO]  Sensor ProjectLinksSensor done: 4 ms
[INFO]  Sensor VersionEventsSensor...
[INFO]  Sensor VersionEventsSensor done: 13 ms
[INFO]  Sensor Maven dependencies...
[INFO]  Sensor Maven dependencies done: 50 ms
[INFO]  Sensor SurefireSensor...
[INFO]  parsing /home/user/workspace/exercise/target/surefire-reports
[INFO]  Sensor SurefireSensor done: 8 ms
[INFO]  Execute decorators...
[INFO]  ANALYSIS SUCCESSFUL, you can browse [url=http://localhost:9000]Domain ist reserviert[/url]
[INFO]  Database optimization...
[INFO]  Deleting files data before Sun Dec 05 02:05:46 CET 2010
[INFO]  Deleting unprocessed data before Sun Dec 05 02:05:46 CET 2010
[INFO]  Database optimization done: 133 ms
[INFO] 
[INFO] --- maven-javadoc-plugin:2.7:jar (javadoc) @ exercise-1-1 ---
[INFO] 
Loading source files for package org.raboss.javaexercise...
Constructing Javadoc information...
Standard Doclet version 1.6.0_22
Building tree for all the packages and classes...
Generating /home/user/workspace/exercise/target/apidocs/org/raboss/javaexercise//ClassDefinition.html...
Generating /home/user/workspace/exercise/target/apidocs/org/raboss/javaexercise//package-frame.html...
Generating /home/user/workspace/exercise/target/apidocs/org/raboss/javaexercise//package-summary.html...
Generating /home/user/workspace/exercise/target/apidocs/org/raboss/javaexercise//package-tree.html...
Generating /home/user/workspace/exercise/target/apidocs/constant-values.html...
Generating /home/user/workspace/exercise/target/apidocs/org/raboss/javaexercise//class-use/ClassDefinition.html...
Generating /home/user/workspace/exercise/target/apidocs/org/raboss/javaexercise//package-use.html...
Building index for all the packages and classes...
Generating /home/user/workspace/exercise/target/apidocs/overview-tree.html...
Generating /home/user/workspace/exercise/target/apidocs/index-all.html...
Generating /home/user/workspace/exercise/target/apidocs/deprecated-list.html...
Building index for all classes...
Generating /home/user/workspace/exercise/target/apidocs/allclasses-frame.html...
Generating /home/user/workspace/exercise/target/apidocs/allclasses-noframe.html...
Generating /home/user/workspace/exercise/target/apidocs/index.html...
3 warnings
[WARNING] Javadoc Warnings
[WARNING] /home/user/workspace/exercise/src/main/java/org/raboss/javaexercise/ClassDefinition.java:3: package org.slf4j does not exist
[WARNING] import org.slf4j.Logger;
[WARNING] ^
[WARNING] /home/user/workspace/exercise/src/main/java/org/raboss/javaexercise/ClassDefinition.java:4: package org.slf4j does not exist
[WARNING] import org.slf4j.LoggerFactory;
[WARNING] ^
[WARNING] /home/user/workspace/exercise/src/main/java/org/raboss/javaexercise/ClassDefinition.java:11: cannot find symbol
[WARNING] symbol  : class Logger
[WARNING] location: class org.raboss.javaexercise.ClassDefinition
[WARNING] static final Logger LOGGER = LoggerFactory.getLogger(ClassDefinition.class);
[WARNING] ^
[INFO] Building jar: /home/user/workspace/exercise/target/exercise-1-1-0.0.1-SNAPSHOT-javadoc.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.192s
[INFO] Finished at: Sun Dec 05 14:05:48 CET 2010
[INFO] Final Memory: 18M/216M
[INFO] ------------------------------------------------------------------------
```

Da ich mit Maven3 (unter Eclipse 3.6 und m2eclipse) arbeite, hier meine pom.xml:
[XML]
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.raboss.javaexercises</groupId>
	<version>0.0.1-SNAPSHOT</version>
	<name>exercise</name>
	<description>ISBN: 978-3-8266-1780-5</description>
	<url>http://www.mitp.de/1780</url>
	<artifactId>exercise-1-1</artifactId>
	<packaging>jar</packaging>
	<dependencies>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-log4j12</artifactId>
		<version>1.6.1</version>
		<type>jar</type>
	</dependency>
	</dependencies>
	<properties>
    	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 	</properties>
	<build>
		<!-- POM Element for Source File Encoding - Maven User - Codehaus
		<sourceEncoding>UTF-8</sourceEncoding>
		//-->
		<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-shade-plugin</artifactId>
			<version>1.4</version>
			<executions>
			<execution>
				<phase>package</phase>
				<goals>
				<goal>shade</goal>
				</goals>
				<configuration>
					<transformers>
					<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
						<manifestEntries>
							<Main-Class>org.raboss.javaexercise.ClassDefinition</Main-Class>
							<Build-Number>20101201</Build-Number>
						</manifestEntries>
					</transformer>
					</transformers>
				</configuration>
			</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.codehaus.sonar</groupId>
			<artifactId>sonar-maven3-plugin</artifactId>
			<version>2.4.1</version>
			<executions>
			<execution>
				<id>sonar</id>
				<!-- phase = compile does not work -->
				<phase>package</phase>
				<goals>
					<goal>sonar</goal>
				</goals>
			</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-javadoc-plugin</artifactId>
			<version>2.7</version>
			<!-- Maven Javadoc Plugin - javadoc:javadoc -->
			<configuration>
				<show>public</show>
				<nohelp>true</nohelp>
				<!-- Maven Javadoc Plugin - Configuring links and offlineLinks Parameters -->
				<links>
				<link>http://www.slf4j.org/apidocs/</link>
				<link>http://download.oracle.com/javase/6/docs/api/</link>
				</links>
				<source>1.6</source>
				<stylesheet>maven</stylesheet>
			</configuration>
			<executions>
			<execution>
				<id>javadoc</id>
				<phase>package</phase>
				<goals>
					<goal>jar</goal>
				</goals>
			</execution>
			</executions>
		</plugin>
		</plugins>
	</build>
</project>
[/XML]

Anschliessend noch das kleine Java-Programm für das JavaDOC erstellt werden soll:

```
package org.raboss.javaexercise;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ClassDefinition {
	private ClassDefinition() {
	}

	// [url=http://logging.apache.org/log4j/1.2/manual.html]Apache log4j 1.2 - Short introduction to log4j[/url]
	static final Logger LOGGER = LoggerFactory.getLogger(ClassDefinition.class);

	/**
	 * @param args
	 */
	public static void main(final String[] args) {
		LOGGER.info("Hallo Welt! Das ist eine einfache Klassendefinition.");
	}
}
```

Ergänzend möchte ich erwähnen, dass eine Verlinkung auf die offizille Java Documentation (Java Platform SE 6) aus dem generierten JavaDOC funktioniert.

Eine weitere zum Thema passender Thread ist Problem with javadoc bullding and combination with JC 2.2.1 documentation. Hier wird von 
	
	
	
	





```
-classpath
```
 als mögliche Ursache für das Derefenzieren von Paketen erwähnt.
Was mich nun stutzig macht ist, dass Package org.apache.maven.plugin.javadoc Description den Parameter 
	
	
	
	





```
-classpath
```
 angeblich automatisch ermittelt. Ich würde es natürlich begrüssen wenn alle relevanten JAR Dateien aus meinem Maven repository und Projekt automatisch übernommen würden, aber ich möchte auf die externen Quellen im Internet verweisen.

Die endgültigen Aufrufparameter für javadoc habe ich der Datei 
	
	
	
	





```
/home/user/workspace/exercise/target/apidocs/options
```
 entnommen:

```
-classpath
'/home/user/workspace/exercise/target/classes'
-encoding
'UTF-8'
-private
-source
'1.6'
-sourcepath
'/home/user/workspace/exercise/src/main/java'
-author
-bottom
'Copyright © 2010. All Rights Reserved.'
-charset
'UTF-8'
-d
'/home/user/workspace/exercise/target/apidocs'
-docencoding
'UTF-8'
-doctitle
'exercise 0.0.1-SNAPSHOT API'
-link
'http://www.slf4j.org/apidocs'
-link
'http://download.oracle.com/javase/6/docs/api'
-link
'http://java.sun.com/javase/6/docs/api'
-nohelp
-stylesheetfile
'/home/user/workspace/exercise/target/apidocs/stylesheet.css'
-use
-version
-windowtitle
'exercise 0.0.1-SNAPSHOT API'
```

Der 
	
	
	
	





```
-classpath '/home/user/workspace/exercise/target/classes'
```
 ist aus meiner Sicht nicht vollständig. Im Verzeichnis 
	
	
	
	





```
>>/target/classes
```
 befinden sich ausschließlich Dateien des aktuellen Projekts aber nicht diejeniegen, die erferenziert werden. Somit kann javadoc die 
	
	
	
	





```
org.slf4j.Logger
```
 und  
	
	
	
	





```
org.slf4j.LoggerFactory
```
 Dokumentation hier nicht finden.

Nun beginnt die Maven3 Magie. Abhängig von der _Phase_ in der das Plugin gestartet wird, ist der _classpath_ unterschiedlich. Wird die _Phase_ von 
	
	
	
	





```
<phase>package</phase>
```
 auf 
	
	
	
	





```
<phase>compile</phase>
```
 geändert:
[XML]
		...
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-javadoc-plugin</artifactId>
			<version>2.7</version>
			<!-- Maven Javadoc Plugin - javadoc:javadoc -->
			<configuration>
				<show>public</show>
				<nohelp>true</nohelp>
				<!-- Maven Javadoc Plugin - Configuring links and offlineLinks Parameters -->
				<links>
				<link>http://www.slf4j.org/apidocs/</link>
				<link>http://download.oracle.com/javase/6/docs/api/</link>
				</links>
				<source>1.6</source>
				<stylesheet>maven</stylesheet>
			</configuration>
			<executions>
			<execution>
				<id>javadoc</id>
				<phase>compile</phase>
				<goals>
					<goal>jar</goal>
				</goals>
			</execution>
			</executions>
		</plugin>
		...
[/XML]

ist der _classpath_ wie erwartet gesetzt. Das beweist ein Blick in die 
	
	
	
	





```
/home/user/workspace/exercise/target/apidocs/options
```
 Datei (hier nur der relevate Inhalt):

```
-classpath
'/home/user/workspace/exercise/target/classes:/home/user/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar:/home/user/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar:/home/user/.m2/repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar'
```

Nun läuft auch 
	
	
	
	





```
maven-javadoc-plugin
```
 fehlerfrei durch, mit Berücksichtigung von 
	
	
	
	





```
<link>
```
 auf die externe JavaDoc Dokumentation.

Wird nun (wie in diesem Fall) 
	
	
	
	





```
sonar-maven3-plugin
```
 verwendet, der wiederum 
	
	
	
	





```
cobertura-maven-plugin
```
 kommt es zu dem Effekt, das 
	
	
	
	





```
maven-javadoc-plugin
```
 zwei mal aufgerufen wird (das gilt natürlich auch für die 
	
	
	
	





```
test
```
 Phase; siehe auch Lifecycle Reference).

Unter diesen Umständen kann 
	
	
	
	





```
sonar-maven3-plugin
```
 (das gilt dann auch für 
	
	
	
	





```
cobertura-maven-plugin
```
) auf die 
	
	
	
	





```
verify
```
 Phase verschoben werden. 
	
	
	
	





```
maven-javadoc-plugin
```
 können wir auf die 
	
	
	
	





```
package
```
 Phase verschieben. Die Phase _verify_ wird im der Phase _package_ nicht berücksichtigt und somit stören sie sich nicht gegenseitig.

Weitere Erkläuterungen und Klarstellungen sind erwünscht.


----------



## kama (5. Dez 2010)

Hallo,

was mich interessiert ist: Warum hast Du das JavaDoc Plugin an die Package phase gebunden und nicht da gelassen wo es ist ...nämlich in der Site Phase wo es auch hingehört ?

Gruß
Karl Heinz Marbaise


----------

