需求:一個父模塊 下面幾個子模塊 其中一個模塊是springboot結構。其他兩個普通jar類型
有許多坑,都在注釋里面寫着呢。注意看父模塊和demo模塊的注釋。
com.imooc.security 父模塊

<?xml version="1.0" encoding="UTF-8"?> <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.imooc.security</groupId> <artifactId>imooc-security</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <!--引入的子模塊--> <modules> <module>imooc-security-core</module> <module>imooc-security-app</module> <module>imooc-security-browser</module> <module>imooc-security-demo</module> </modules> <!--版本控制參數,在父項目里面聲明。--> <properties> <imooc.security.version>1.0-SNAPSHOT</imooc.security.version> </properties> <!--下面兩個是版本管理,意識就是說引入這兩個之后,他下面的子模塊如果引入依賴就不用寫版本號了 ,他倆給你們做了,自動引入版本號,避免因為引入的版本不兼容而引起的錯誤--> <dependencyManagement> <dependencies> <dependency> <groupId>io.spring.platform</groupId> <artifactId>platform-bom</artifactId> <version>Brussels-SR4</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!--父項目編譯插件--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
imooc-security-core 子模塊

<?xml version="1.0" encoding="UTF-8"?> <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> <artifactId>imooc-security</artifactId> <groupId>com.imooc.security</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>imooc-security-core</artifactId> <dependencies> <!--主要引入springseurity和oauth相關的jar,很重要的jar--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-oauth2</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--第三方登陸相關 begin--> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-config</artifactId> </dependency> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-core</artifactId> </dependency> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-security</artifactId> </dependency> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-web</artifactId> </dependency> <!--第三方登陸相關 end--> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> </dependency> <!--加速開發的工具,可以省略getset和日志類,只需要注解就可以--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> </dependency> </dependencies> </project>
imooc-security-browser 子模塊

<?xml version="1.0" encoding="UTF-8"?> <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> <artifactId>imooc-security</artifactId> <groupId>com.imooc.security</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>imooc-security-browser</artifactId> <dependencies> <dependency> <groupId>com.imooc.security</groupId> <artifactId>imooc-security-core</artifactId> <version>${imooc.security.version}</version> </dependency> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session</artifactId> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>1.2.2</version> </dependency> </dependencies> </project>
imooc-security-demo 子模塊(這個模塊是springboot結構,需要生成的jar可以跑在瀏覽器的)

<?xml version="1.0" encoding="UTF-8"?> <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> <artifactId>imooc-security</artifactId> <groupId>com.imooc.security</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>imooc-security-demo</artifactId> <dependencies> <dependency> <groupId>com.imooc.security</groupId> <artifactId>imooc-security-browser</artifactId> <version>${imooc.security.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock</artifactId> </dependency> </dependencies> <!--這個是springboot的編譯插件,如果不引入他的話,直接在父項目中執行打包命令,也會成功,但是所生成的 jar包里面沒有依賴,只有幾k大小,不知道為啥,所以我們要引入這個插件,幫助我們再次打包,原來的 也保留,只不過是xx.jar.original這種類型,xxxxx.jar是這個插件打包的jar。 然后執行java -jar filename.jar 就ok了 repackage的意思是重新打包的意思必須加 包名就是下面的 finalName --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.0.1.RELEASE</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> <finalName>demo</finalName> </build> </project>