A simple example about Maven from a textbook

621 views Asked by At

I am using Apache Maven 3.6.0.

I'm studying a book on Maven, namely this one: https://books.sonatype.com/mvnex-book/pdf/mvnex-pdf.pdf. Page 7 / 155.

We are given a Sample Maven pom.xml:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.sonatype.mavenbook</groupId>
    <artifactId>my-project</artifactId>
    <version>1.0-SNAPSHOT</version>
</project>

Then it is written that we should run:

mvn install 

I tried, it is OK. Target directory is created.

Then it is written: "Without modification, you can run mvn site".

I did that and get this: https://pastebin.com/9Zrmws9T

Well, it seems that something has to do with maven-site-plugin. But I don't know what this means for me, or whether the book is worth reading, given that it turns such somersaults at the very beginning.

Can I fix this problem with Maven?

2

There are 2 answers

1
Essex Boy On BEST ANSWER

Best way to learn maven is to start.

Let maven create an example project from an archetype:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE


[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:3.0.0:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:3.0.0:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] 
[INFO] --- maven-archetype-plugin:3.0.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [org.apache.maven.archetypes:maven-archetype-quickstart:1.4] found in catalog remote
Define value for property 'groupId': com.essexboy
Define value for property 'artifactId': site-example
Define value for property 'version' 1.0-SNAPSHOT: : 
Define value for property 'package' com.essexboy: : 
Confirm properties configuration:
groupId: com.essexboy
artifactId: site-example
version: 1.0-SNAPSHOT
package: com.essexboy
 Y: : 
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.essexboy
[INFO] Parameter: artifactId, Value: site-example
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.essexboy
[INFO] Parameter: packageInPathFormat, Value: com/essexboy
[INFO] Parameter: package, Value: com.essexboy
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: com.essexboy
[INFO] Parameter: artifactId, Value: site-example
[INFO] Project created from Archetype in dir: /home/greg/work/site-example
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  24.041 s
[INFO] Finished at: 2020-09-30T11:40:30+01:00
[INFO] ------------------------------------------------------------------------

Change directory into your new project where you'll have a pom and some code.

greg@greg-XPS-13-9360:~/work$ cd site-example/

Run the site command

greg@greg-XPS-13-9360:~/work/site-example$ mvn site

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.essexboy:site-example >----------------------
[INFO] Building site-example 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-site-plugin:3.7.1:site (default-site) @ site-example ---
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:3.0.0
[INFO] 15 reports detected for maven-project-info-reports-plugin:3.0.0: ci-management, dependencies, dependency-info, dependency-management, distribution-management, index, issue-management, licenses, mailing-lists, modules, plugin-management, plugins, scm, summary, team
[INFO] Rendering site with default locale English (en)
[INFO] Relativizing decoration links with respect to localized project URL: http://www.example.com
[INFO] Rendering content with org.apache.maven.skins:maven-default-skin:jar:1.2 skin.
[INFO] Generating "Dependencies" report  --- maven-project-info-reports-plugin:3.0.0:dependencies
[INFO] Generating "Dependency Information" report --- maven-project-info-reports-plugin:3.0.0:dependency-info
[INFO] Generating "About" report         --- maven-project-info-reports-plugin:3.0.0:index
[INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:3.0.0:plugin-management
[INFO] Generating "Plugins" report       --- maven-project-info-reports-plugin:3.0.0:plugins
[INFO] Generating "Summary" report       --- maven-project-info-reports-plugin:3.0.0:summary
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.829 s
[INFO] Finished at: 2020-09-30T11:40:46+01:00
[INFO] ------------------------------------------------------------------------

Your site will be generated under target/site. You can open the index.html in a browser:

enter image description here

0
hinson On

Yes, the example from the book didn't seem to work for me either.

However, after I added the following build/plugins section into the pom.xml, mvn site started to work for me:

<build>
<plugins>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-site-plugin</artifactId>
  <version>3.7.1</version>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-project-info-reports-plugin</artifactId>
  <version>3.0.0</version>
</plugin>
</plugins>
</build>

Please, also take a look at this answer here: maven-site plugins 3.3 java.lang.ClassNotFoundException: org.apache.maven.doxia.siterenderer.DocumentContent