Reputation: 417
I get the following error when I run mvn javadoc:javadoc
[ERROR] Exit code: 1 - javadoc: error - Illegal package name: "edu.princeton.cs.1-Fundamentals.1-1-BasicProgModel"
The reason I pretty clear but I don't know how to solve it.
This is my src file structure in the folder src/main/java/edu/princeton/cs/
.
├── 1-Fundamentals
│ ├── 1-1-BasicProgModel
│ ├── 1-2-DataAbstraction
│ ├── 1-3-BagsQueuesStacks
│ ├── 1-4-AnalysisOfAlgorithms
│ └── 1-5-UnionFind
├── 2-Sorting
│ ├── 2-1-ElementarySorts
│ ├── 2-2-Mergesort
In each directory, the java code contains package edu.princeton.cs.algs4
;
That means the folder name is not the package name. However, the javadoc mistakenly think the folder name is the package name.
How can I let maven know that there are no package like edu.princeton.cs.1-Fundamentals.1-1-BasicProgModel
Upvotes: 1
Views: 4383
Reputation: 1
Does your path contain spaces. If any directory name contains spaces then javadoc plugin seems to fail.
Example:
Bad route: My Project/Project java/My new game
Good route: MyProject/Project-java/My-new-game
Upvotes: 0
Reputation: 2126
You are trying to use Maven against it's convention. By default, and unless stated explicitly, the source root of your project is under src/main/java
. This means that any directory below will be considered a part of package name, and as such must match package name declared in the .java source files.
Now, you can override the convention, and tell Maven to consider another directory a sources root, so that javac or javadoc work as expected:
::pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<!--Overrides the default:-->
<!--<sourceDirectory>src/main/java</sourceDirectory>-->
<sourceDirectory>./path/relative/to/pom.xml/</sourceDirectory>
</build>
</project>
Since you have multiple sources roots in this project, you may consider adding separate pom.xml for each, or changing the layout and add other sources directories with additional plugin in pom.xml:
Project structure:
Project Directory
├── 1-Fundamentals
│ ├── 1-1-BasicProgModel
│ │ ├──src
│ │ │ └──edu/princeton/cs/algs4 (only classes and directories matching packages)
│ │ │ ├── JavaClass1.java
│ │ │ └── JavaClass2.java
│ │ └── other non source content
│ ├── 1-2-DataAbstraction
│ │ ├──src
│ │ │ └──edu/princeton/cs/algs4
│ │ │ ├── JavaClass3.java
│ │ │ └── JavaClass4.java
│ │ └── other non source content
│ └── 1-3-BagsQueuesStacks
│ ├──src
│ │ └──edu/princeton/cs/algs4
│ │ ├── JavaClass5.java
│ │ └── JavaClass6.java
│ └── other non source content
└── pom.xml
And tell maven where are source roots:
<?xml version="1.0" encoding="UTF-8"?>
<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>example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>1-Fundamentals/1-1-BasicProgModel/src</source>
<source>1-Fundamentals/1-2-DataAbstraction/src</source>
<source>1-Fundamentals/1-3-BagsQueuesStacks/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Upvotes: 1