我想制作一个war文件,在一个apache tomcat服务器中部署angular2项目。我做了一个maven项目并在其中插入了angular2项目。然后我使用angular-cli在maven项目的src / main中创建了webapp文件夹(而不是angular2项目中的dist文件夹)。当我运行apache服务器时,它显示以下错误。
从http://localhost:8080/vendor/angularfire2/angularfire2.js加载http://localhost:8080/app/app.module.js为“angularfire2”时出错;区域:;任务:Promise.then;值:错误:错误:XHR错误(未找到404)加载http://localhost:8080/traceur(...)null
看起来麻烦的依赖是angularfire2。怎么算这个我们的?顺便说一下,我使用angular2 rc-5。
答案 0 :(得分:1)
由于对此问题有很多看法,我想对此问题发表完整的答案。
答案适用于所有2+版本。
步骤如下。
首先,您需要在项目的根目录中创建一个POM文件。在POM中包含以下代码
<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 http://maven.apache.org/POM/4.0.0 ">
<modelVersion>4.0.0</modelVersion>
<groupId>it.your-company</groupId>
<artifactId>your-project-artifact-id</artifactId>
<version>1.0.0</version>
<name>your-project-name</name>
<description>Any description</description>
<packaging>war</packaging>
<build>
<finalName>target-file-name</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>dist</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.build.finalName}</path>
<update>true</update>
<url>http://localhost:8080/manager/text</url>
<username>tomcat</username>
<password>tomcat321</password>
</configuration>
</plugin>
</plugins>
</build>
在这里,我包括了用于构建war文件的maven war插件以及使用IntelliJ想法进行战争的maven tomcat插件。
然后,您需要将index.html文件的基本URL更改为 base href =“ / target-file-name” 。 如果您使用maven tomcat插件进行战争,则应用程序的URL为http://localhost:8080/target-file-name
现在使用 ng build --prod 构建您的角度项目。这将在dist文件夹中创建所有必需的部署文件(构建文件)。
现在运行 mvn clean package 将构建文件打包为war文件。 war文件将在项目的根目录下的目标文件夹中创建。
答案 1 :(得分:0)
如果要在本地部署。具体说一下localhost:8080(Tomcat),转到service.msc并启动tomcat Services。使用(ng build)构建角度2 /角度4。现在打开angular项目文件夹并将dist文件夹中的文件复制到一个新文件夹(webui)。打开index.html页面并给出as。将此文件夹复制到&#34; C:\ Program Files \ Apache Software Foundation \ Tomcat 8.0 \ webapps&#34;。转到浏览器并键入localhost:8080 / webui。
这是我在tomcat中部署我的angular 4静态内容的方式。 希望这对你有所帮助。
答案 2 :(得分:0)
在index.html中将基本href设置为“”或在您的情况下(tomcat)设置为适用于我的“webapps”