我在这里阅读了一些关于以前 maven 问题的有用帖子,我目前对学习 maven 非常感兴趣(因为我喜欢它,因为我的老板要求我这样做)。我目前正在阅读 [this][1] 书,并且正在通过示例进行工作。这是一本简单的书,但里面有一些错误(微不足道的错误),但是对于像我这样的新手来说很难发现,一旦发现它就可以轻松修复。有没有其他书更好地从上到下理解maven?
问题的第二部分是与本书中的一个例子有关,也许一个简单的解释可以解决我的疑问。
事情是这样的,我simple-weather
在java中做了一个项目,它从雅虎天气服务器检索天气状况,给定它返回天气信息的特定邮政编码。
然后我做了一个'simple-webapp'(使用maven以及上面我忘了提到的那个),它基本上是一个web项目,它已经有一些默认的servlet和maven,它什么都不做。
我有一些parent-project
我想将这两个项目合并为一个,所以我制作了一个 pom.xml,它有 2 个模块,1 个用于检索信息(java 项目),另一个用于在网络上显示它(网络应用程序)。
我最终使一切正常,但奇怪的是..如果我让 webapp 显示任何字符串“名称”,让我们说然后独立构建它,它确实会打印该字符串。但是,当我将 webapp 放入“父项目”并将此字符串更改为“name1”并将其构建为 sa partent-project 子模块时..没有任何变化..
所以我回到正题,因为 simple-webapp 依赖于 simple-weather 我不能再单独构建它,所以现在如果我想对 webapp 进行一些更改.. 在“parent-”之外修改 webapp项目”在那里构建它,然后将其粘贴回父项目,然后更改将应用,为什么会这样,为什么我不能直接更改 servlet 内容/或在 webapp 中添加另一个作为“父项目”的一部分-项目”?
谢谢..我知道这是一个又长又无聊的问题,但我只是想学习一些东西,没有比这里更好的地方了:D
编辑 - 这里是每个项目的 POM 文件:
1. 简单父 pom.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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Multi Chapter Simple Parent Project</name>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2.简单天气pom.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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-weather</artifactId>
<packaging>jar</packaging>
<name>Multi Chapter Simple Weather API</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
3. simple-webapp pom.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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-webapp</artifactId>
<packaging>war</packaging>
<name>simple-webapp Maven Webapp</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-weather</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>