一、Eclipse下Maven的父子結構展現
java
二、建立父項目,pom文件web
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.curtain</groupId> <artifactId>frame</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>Curtain</name> <!-- 打包的時候,執行順序 parent:防止全部依賴JAR console:自定義的JAR(能夠理解爲項目的後端代碼打包) web:放置配置文件、相關頁面 --> <modules> <module>curtain-parent</module> <module>curtain-console</module> <module>curtain-web</module> </modules> </project>
三、建立子項目parent,pom文件spring
<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/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.curtain</groupId> <artifactId>frame</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.curtain.frame</groupId> <artifactId>curtain-parent</artifactId> <packaging>pom</packaging> <!--定製屬性--> <properties> <java-version>1.7</java-version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <testFailureIgnore>true</testFailureIgnore> <test.skip>true</test.skip> <org.springframework-version>4.2.0.RC3</org.springframework-version> </properties> <!--依賴包--> <dependencies> <!-- SPRING --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${org.springframework-version}</version> <exclusions> <!-- Exclude Commons Logging in favor of SLF4j --> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${org.springframework-version}</version> </dependency> <!-- SPRING WEBSOCKET --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-messaging</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-websocket</artifactId> <version>${org.springframework-version}</version> </dependency> </dependencies> <build> <plugins> <!--插件版本--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java-version}</source> <target>${java-version}</target> </configuration> </plugin> <!--插件跳過測試--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>${test.skip}</skip> <testFailureIgnore>${testFailureIgnore}</testFailureIgnore> </configuration> </plugin> <!--插件生命週期--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-source</id> <phase>package</phase><!-- 要綁定到的生命週期的階段 --> <goals> <goal>jar-no-fork</goal><!-- 要綁定的插件的目標 --> </goals> </execution> </executions> </plugin> </plugins> </build> <repositories> <repository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </repository> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>false</enabled> </releases> </repository> <repository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <profiles> <!--私服地址--> <profile> <id>wuhan_maven</id> <activation> <activeByDefault>true</activeByDefault> </activation> <distributionManagement> <snapshotRepository> <id>snapshots</id> <url>http://ip:port/nexus/content/repositories/snapshots/</url> </snapshotRepository> <repository> <id>releases</id> <url>http://ip:port/nexus/content/repositories/releases/</url> </repository> </distributionManagement> </profile> <profile> <id>beijing_maven</id> <distributionManagement> <snapshotRepository> <id>snapshots</id> <url>http://ip:port/nexus/content/repositories/snapshots/</url> </snapshotRepository> <repository> <id>id</id> <url>http://ip:port/nexus/content/repositories/releases/</url> </repository> </distributionManagement> </profile> </profiles> </project>
四、建立子項目console,JAR文件apache
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.curtain</groupId> <artifactId>frame</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.curtain.frame</groupId> <artifactId>curtain-console</artifactId> </project>
五、建立子項目web,WAR文件後端
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- <parent> <groupId>com.curtain.farme</groupId> <artifactId>curtain-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> --> <parent> <groupId>com.curtain</groupId> <artifactId>frame</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.curtain.farme</groupId> <artifactId>curtain-web</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>curtain-web</name> <dependencies> </dependencies> <!--編譯並運行tomcat: war:exploded tomcat7:run --> <!--打包代碼: install --> <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <!-- class文件會自動打JAR包 --> <archiveClasses>false</archiveClasses> <failOnMissingWebXml>false</failOnMissingWebXml> <!--覆蓋--> <overlays> <overlay> <groupId>com.curtain.farme</groupId> <artifactId>curtain-web</artifactId> </overlay> </overlays> </configuration> </plugin> </plugins> </build> </project>
六、運行父項目的POM文件,打包效果
tomcat
注意:websocket
一、新建Maven項目,勾選這個,免去選擇模板
mvc
二、想要顯示父子結構,除了要按照這樣添加POM以外,還須要在父項目的POM中設置socket
2.1Add是添加已存在的Maven項目在父項目下maven
2.2Create是建立一個新的Maven項目在父項目下