让我先说一下,我是Maven /
Spring的新手,当我的目录不遵循首选的Maven结构时,我很难搞清楚要做什么.
我通过这个tutorial遵循了使用Angular 2和Spring Boot设置项目的说明.本教程创建了两个模块,前端和后端,以及相应的pom.xml和一个父pom.xml.我可以使用我的IDE,IntelliJ或从后端目录运行“mvn spring-boot:run”来运行应用程序.但是,对于部署,我希望将应用程序打包到WAR文件中以放入Tomcat服务器.我不确定如何使用我目前拥有的pom.xml来做到这一点.我很确定它与我的目录结构有关,但是我不确定是否应该重构我的应用程序,或者有一种方法可以配置Maven将这两个模块放入生成预期的WAR文件中.
我找到了类似的答案here,但最后一部分是什么让我失望.我没有/ src / main / webapp / WEB-INF文件夹,我不确定在哪里制作它.
我的申请结构如下:
AppRoot -backend --src ---main ----java --pom.xml -frontend --src ---main ----frontend --pom.xml -pom.xml
我的root pom.xml是:
<groupId>com.trinityinnovations</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>c-cop</name> <description>C-COP Project</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <modules> <module>frontend</module> <module>backend</module> <module>web</module>
前端pom.xml:
<artifactId>frontend</artifactId> <name>frontend</name> <description>C-COP Project frontend</description> <parent> <groupId>com.trinityinnovations</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <build> <plugins> <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.3</version> <configuration> <nodeVersion>v6.9.1</nodeVersion> <npmVersion>4.0.3</npmVersion> <workingDirectory>src/main/frontend</workingDirectory> </configuration> <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> </execution> <execution> <id>npm install</id> <goals> <goal>npm</goal> </goals> </execution> <execution> <id>npm run build</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>run build</arguments> </configuration> </execution> </executions> </plugin> </plugins> <resources> <resource> <directory>target/frontend</directory> <targetPath>static</targetPath> </resource> </resources> </build>
后端pom.xml:
<artifactId>backend</artifactId> <name>backend</name> <description>C-COP Project backend</description> <parent> <groupId>com.trinityinnovations</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.restdocs</groupId> <artifactId>spring-restdocs-mockmvc</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.trinityinnovations</groupId> <artifactId>frontend</artifactId> <version>${project.version}</version> <scope>runtime</scope> </dependency> <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient --> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-csv --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-csv</artifactId> <version>1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/MysqL/MysqL-connector-java --> <dependency> <groupId>MysqL</groupId> <artifactId>MysqL-connector-java</artifactId> <version>6.0.6</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-hibernate5</artifactId> </dependency> <dependency> <groupId>com.javaetmoi.core</groupId> <artifactId>javaetmoi-hibernate5-hydrate</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>com.google.maps</groupId> <artifactId>google-maps-services</artifactId> <version>0.1.20</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
如果有更多信息需要,请告诉我.
经过大量的搜索后,我遇到了
Maven War Plugin.这使我能够将必要的前端文件拉到后端,以便成功创建我的WAR文件.需要进行的更改如下:
原文链接:https://www.f2er.com/angularjs/240408.html<packaging>war</packaging>
<plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <webResources> <resource> <directory>../frontend/target/frontend</directory> </resource> </webResources> </configuration> </plugin>
除此之外,您可以保持现有的pom.xml与仅后端pom.xml需要包含war包装相同.它最终成为一个相当简单的答案.
还需要在package.json中设置base-href.注意“构建”:
"scripts": { "ng": "ng","start": "ng serve --proxy-config proxy.conf.json","test": "ng test","lint": "ng lint","e2e": "ng e2e","build": "ng build --base-href=\"./\"" },