【问题标题】:A simple example about Maven from a textbook教科书中关于 Maven 的简单示例
【发布时间】:2021-01-15 23:03:16
【问题描述】:

我正在使用 Apache Maven 3.6.0。

我正在研究一本关于 Maven 的书,即这本书: https://books.sonatype.com/mvnex-book/pdf/mvnex-pdf.pdf。第 7 页 / 155 页。

我们得到了一个示例 Maven pom.xml:

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

然后写到我们应该运行:

mvn install 

我试过了,没问题。目标目录已创建。

然后写成:“无需修改,就可以运行mvn site”。

我这样做并得到了这个:https://pastebin.com/9Zrmws9T

嗯,似乎与 maven-site-plugin 有关。但我不知道这对我意味着什么,也不知道这本书是否值得一读,因为它一开始就翻了个筋斗。

我可以用 Maven 解决这个问题吗?

【问题讨论】:

标签: maven maven-site-plugin


【解决方案1】:

学习 maven 的最佳方式是开始。

让 maven 从 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] ------------------------------------------------------------------------

将目录更改为您的新项目,您将在其中拥有一个 pom 和一些代码。

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

运行站点命令

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] ------------------------------------------------------------------------

您的站点将在目标/站点下生成。您可以在浏览器中打开 index.html:

【讨论】:

  • 这如何解决实际问题?
【解决方案2】:

是的,书中的例子似乎也不适合我。

但是,在我将以下构建/插件部分添加到 pom.xml 后,mvn site 开始为我工作:

<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>

请在此处查看此答案: maven-site plugins 3.3 java.lang.ClassNotFoundException: org.apache.maven.doxia.siterenderer.DocumentContent

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多