Thy Dai Thy Dai - 5 months ago 52
Java Question

How do I change the package for Javadoc to find source files?

I have a Mavenized project and I'm using Eclipse (but I'm also having this issue running it from cmd) with Java 1.6.0_45, and I am trying to run the command:

mvn package


Here is my project:
Project Layout

My project name is cycle-server, and my Main.java is within a test package under src/main/java.

cycle-server
--> src/main/java
--> test
--> Main.java
--> src/main/resources
--> src/test/java
--> src/test/resources
--> Referenced Libraries
--> JRE System Library [JavaSE-1.6]
--> doc
--> src
--> main
--> assembly
--> assembly.xml
--> test
--> target
--> pom.xml


When I run the above command: I receive this error:

Loading source files for package main.java.test...
Constructing Javadoc information...
1 error
1 warning
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] MavenReportException: Error while creating archive:
Exit code: 1 - javadoc: warning - No source files for package main.java.test
javadoc: error - No public or protected classes found to document.

Command line was: "C:\Program Files (x86)\Java\jdk1.6.0_45\jre\..\bin\javadoc.exe" @options @packages

Refer to the generated Javadoc files in 'C:\Users\Thy\eclipse\workspace\cycle-server\target\apidocs' dir.


I have pinpointed my problem to the package that Javadoc is looking in: main.java.test. If it was just test, I believe I would be able to successfully build. Is there anyway to fix this Javadoc location path for both Eclipse and command line?

I have tried changing the package name, and also changing the source folders within the project. I would like to keep my folders the way they are.

A Javadoc is REQUIRED for the assignment, and I would not like to skip the Javadoc generation.

EDIT: Here is my pom.xml. I have removed a few dependencies because they are company specific.

<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>
<parent>
<groupId>COMPANY PARENT POM</groupId>
<artifactId>COMPANY MAVEN PARENT POM</artifactId>
<version>2.1</version>
</parent>
<groupId>test</groupId>
<artifactId>cycle-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cycle-server</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<repositories>
<!-- Tell Maven where to find the parent POM -->
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>COMPANY PARENT POM</id>
<name>COMPANY PARENT POM REPO</name>
<url>REPO URL</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.google.code.sortpom</groupId>
<artifactId>maven-sortpom-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sort</goal>
</goals>
</execution>
</executions>
<configuration>
<lineSeparator>\n</lineSeparator>
<keepBlankLines>true</keepBlankLines>
<sortDependencies>scope,artifactId</sortDependencies>
<nrOfIndentSpace>-1</nrOfIndentSpace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>test.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>snapshot</id>
<activation>
<property>
<name>maven.perform.snapshot</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
</project>

Answer

The <sourceDirectory> is wrong. It should be either

<sourceDirectory>src/main/java</sourceDirectory>

or not specified at all, as this is the default. This is why it is complaining about "package main.java.test", because that's not a real package.

Comments