Angular2& Spring启动将angular2应用程序构建为war文件

时间:2018-03-22 08:41:49

标签: java angular spring-boot

我有一个angular2应用程序(MyNewApp)和Spring启动应用程序(MyNewAppROOT)来构建一个war文件以部署在tomcat服务器中。在MyNewAppROOT应用程序中,有一些代理控制器如下所示。

@Controller
public class ProxyController
{

    @RequestMapping(value = "/api/**", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String mirrorMyBoxAny( HttpMethod method, HttpServletRequest request, HttpServletResponse response )
    {
        return ProxyService.exchange( method, request, response );
    }

    public static void main(String args[])
    {

    }

}

另一个代理。

@RestController
public class MyNewAppController
{

    @RequestMapping(method = { RequestMethod.POST }, value = "my-dashboard/**", produces = "application/json")
    public String getStatistics( HttpMethod method, HttpServletRequest request, HttpServletResponse response )
    {
        //content
    }
}

的pom.xml

<?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>it.my.app.web</groupId>
    <artifactId>MyNewApp</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <war.name>ROOT</war.name>
        <war.path>${project.basedir}/target/ROOT.war</war.path>
        <deploy.module.name>MyNewApp</deploy.module.name>
        <app.localrepository.common>http://artifacts.my.net/artifactory/project-libs</app.localrepository.common>
    </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-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
        <pluginRepository>
            <id>my-repo</id>
            <name>my Intranet Maven Repository</name>
            <url>${app.localrepository.common}</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--Build Info Goal-->
                <executions>
                    <execution>
                        <goals>
                            <goal>build-info</goal>
                        </goals>
                        <configuration>
                            <additionalProperties>
                                <number>${buildNumber}</number>
                            </additionalProperties>
                            <outputFile>${basedir}\src\main\resources\properties\build-info.properties</outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <!-- here the phase you need -->
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/ROOT</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>../MyNewApp/dist</directory>
                                    <filtering>false</filtering>
                                </resource>
                                <resource>
                                    <directory>../MyNewAppUI/src/app/styles/</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!--Use ant-contrib for Task IF -->
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties">
                                    <classpath>
                                        <pathelement location="${ant-contrib:ant-contrib:jar}"/>
                                    </classpath>
                                </taskdef>

                                <!--Deploy the war file created by the profile -->
                                <!--deploy.module.name parameter is used to define the module to
                                    be uploaded when the -->
                                <!--war file name is differ from the module name -->
                                <echo>Jenkins Server ref : ${server}</echo>
                                <echo>deploy.module.name : ${deploy.module.name}</echo>
                                <echo>war.name : ${war.name}</echo>
                                <echo>war.path : ${war.path}</echo>
                                <if>
                                    <or>
                                        <and>
                                            <isset property="deploy.module.name"/>
                                            <equals arg1="${project.name}" arg2="${deploy.module.name}"/>
                                        </and>
                                    </or>
                                    <then>
                                        <property name="cganthelper.path" value="${it.my:CGAntHelper:jar}"/>
                                        <taskdef name="deployTask" classname="it.my.ant.Deploy"
                                                 classpath="${cganthelper.path}"/>
                                        <echo>war.path : ${war.path}</echo>
                                        <deployTask serverRef="${server}" type="dist"
                                                    file="${war.path}" autodeploy="${deploy.auto}"/>
                                    </then>
                                </if>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>1.0b3</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!--Build Number Plugin-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>ex1</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <revisionOnScmFailure>unknown</revisionOnScmFailure>
                    <format>{0}</format>
                    <items>
                        <item>buildNumber</item>
                    </items>
                    <doCheck>false</doCheck>
                    <doUpdate>false</doUpdate>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <scm>
        <connection>scm:svn:http://none</connection>
        <developerConnection>scm:svn:https://none</developerConnection>
        <url>scm:svn:https://none</url>
    </scm>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>

        <!--<repository>-->
            <!--<id>spring-releases</id>-->
            <!--<url>https://repo.maven.apache.org/maven2/</url>-->
        <!--</repository>-->
    </repositories>

    <distributionManagement>
        <repository>

        </repository>
    </distributionManagement>

</project>

proxy.config.json

{
  "/api": {
    "target": "http://111.111.0.1:3003",
    "secure": false,
    "pathRewrite": {
      "^/api": ""
    },
    "changeOrigin": true
  }
}

首先,我运行命令 ng build --prod 来创建 dist 文件夹。之后执行全新安装,以便创建ROOT.war文件。

但我的要求是使用不同的名称创建一个war文件,例如 my-app.war NOT ROOT.war。

如何更改我的pom文件以及如何构建MyNewApp angular2应用程序以使用它?

任何建议都表示赞赏。

谢谢!

0 个答案:

没有答案