我读了一些有用的职位这里在使关于以前的家的问题,目前,我正在非常感兴趣学习家(因为我喜欢它,因为我的老板要求我).目前,我正在读[这][1]书和我的工作我的方式槽的例子。它是一个简单的书,但其中有一些错误的内部(微不足道的人),但对于一个像我这样的新手可能很难点,一旦发现它可以很容易地固定的。是否有任何其他书更好地了解家从上到底?

第二部分问题是有关的一个例子,在这本书了,也许一个简单的解释将会解决我的疑虑。

这里是东西,我做了一个 simple-weather 项目java检索的天气条件下从雅虎的天气服务器,给予特别的邮政编码返回的气象信息。

然后我做了一个简单-webapp'(与专家以及一个以上的我忘了提这一),这是。不大;一个网络项目,该项目有一定的默认servlet已经在那里与家和它什么都不做。

和我有一些 parent-project 我想要合并这两个项目之一,所以我做了一个pom.xml 其中有2个模块、1检索信息(java项目)和其它来显示它在网络(网络应用程序).

我做的一切工作的结束,但这里是奇怪的事情..如果我做webapp显示任何串的"名称"可以说,随后建立独立,它并完全打印的字符串。但当我把webapp在"父母"项目,并改变这一串"name1",并建立它作为sa partent项目分模块..没有什么变化..

所以我回到这一点,因为简单的网络应用程序是依赖简单的天气,我可不建立了自己,所以现在如果我想做一些改变,以webapp..修改的网络应用程序以外的"父母"项目建立这有那么粘贴回到父母的项目和随后的改变将适用,这是为什么,为什么我不能直接更改servlet内容/或增加的另一个网络应用程序的一部分的"父母"的项目?

谢谢你..我知道它是一个长期和无聊的问题,但我只是想要学习的东西并没有更好的地方问于: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.简单的网络应用程序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>
有帮助吗?

解决方案

我不一定要完全明白你的问题。然而,让我们解释一些原则在家.

所以你必须这样一种结构:

parent
  + simple-weather
  + simple-webapp

在专家的观点,我们有3个项目:

  • , ,这是一个 pom 项目(即它的 packaging 属性设定为 pom)
  • 简单的天气, ,这是一个 jar 项目 作为父母。
  • 简单的网络应用程序, ,这是一个 war 的项目,已 作为父母 简单的天气 作为依赖。

父项目将使用两个概念在家:

  • 继承,其中说,他的所有儿童(简单的天气简单的网络应用程序)将继承他的所有属性(这一概念几乎是同样的事情的 extends 在Java)。
  • 聚合,其定义是,通过的定义 <modules>.聚集意味着,每一个命令,将运行在该项目还将运行在每 module.

什么发生,如果我建立的(使用 mvn clean install)在 目录?

  1. 专家会"汇编"的 项目然后 安装 的pom.xml 在当地的存储库。
  2. 专家将汇编 简单的天气 的项目,但它有一个父母、家将看父母pom.xml 文件进当地的存储库。一旦罐子是创建的,它是安装在地存储库。
  3. 专家将最后编制的 简单的网络应用程序 的项目。专家将做同样的事情的父母pom.xml但也对 简单的天气 的项目。

该情况说明中的第3点是很重要的:如果你想要建立的 简单的网络应用程序 的项目,专家会 总是 试图找到他的所有依赖性,包括 简单的天气 -从地方(或遥远的)存储库。

这就是为什么如果你仅仅建立 简单的网络应用程序 没有建筑和安装 简单的天气,家不会找到后者的项目,或者将会找到一个旧的版本。

所以总结一下,在你工作在多模块项目专家,尝试总是运行建立和安装的命令从根(或父母)的目录。

我希望,这种解释是不够清晰和帮助你理解什么发生在你的情况。毫不犹豫地要求更多的信息...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top