我在這裏閱讀了關於以前的maven問題的一些有用的帖子,我目前對學習maven非常感興趣(因爲我喜歡它,因爲我的老闆需要我)。我目前正在閱讀[這本] [1]一書,我正在通過例子工作。它是一本簡單明瞭的書,但其內部存在一些錯誤(瑣碎的),但對於像我這樣的新手來說,很難發現,一旦發現它可以很容易地修復。有沒有其他書更好地理解從上到下的maven?問題的關於maven的問題
第二部分是關於一個例子,這本書,也許一個簡單的解釋就解決了我的懷疑。
這是事情,我做了一個simple-weather
項目在Java中檢索從雅虎天氣服務器的天氣條件,給予特定的郵政編碼,它返回天氣信息。
然後我做了一個'simple-webapp'(帶有maven以及上面我忘記提到的那個),這基本上是一個web項目,它有一些默認的servlet已經與maven一起使用,它什麼都不做。我想要將這兩個項目合併爲一個,所以我創建了一個包含2個模塊的pom.xml,其中包含1個用於檢索信息(java項目)和其他信息以將其顯示在Web(Web應用程序)上的信息。
我在結束了一切工作,但這裏是奇怪的事情。如果我做的webapp顯示任何字符串「name」可以說,然後獨立打造它,它不正是打印字符串。但是,當我把webapp放在「父項目」中,並將此字符串更改爲「name1」並將其構建爲一個partent-project子模塊時。沒有任何更改..
因此,我回到了這一點,因爲簡單的webapp是依賴於簡單的天氣我不能再建立它自己,所以現在,如果我想對webapp做一些更改..修改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.簡單的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>
請解釋您運行的目標以及從哪裏運行。 – 2010-02-05 16:38:54
我正在運行,maven clean,然後從父pom.xml安裝maven – 2010-02-08 09:36:43