Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于Angular 7应用程序的Tomcat上的图像路径_Angular_Ubuntu_Tomcat_Deployment - Fatal编程技术网

用于Angular 7应用程序的Tomcat上的图像路径

用于Angular 7应用程序的Tomcat上的图像路径,angular,ubuntu,tomcat,deployment,Angular,Ubuntu,Tomcat,Deployment,我在Windows机器(Windows 10,Visual Studio代码1.30.2)和运行在AWS上的Ubuntu18.04服务器上的Tomcat 9上进行本地开发时遇到不同的映像源路径问题。在Powershell中基于Windows 10构建,具有: ng build --prod --base-href /myapp/ 顺便说一句,如果用GitBash构建,它会完全弄乱路径,不要这样做 如果我希望此应用程序在本地windows计算机上运行,并且如果我希望具有指向图像源的可单击(在VS

我在Windows机器(Windows 10,Visual Studio代码1.30.2)和运行在AWS上的Ubuntu18.04服务器上的Tomcat 9上进行本地开发时遇到不同的映像源路径问题。在Powershell中基于Windows 10构建,具有:

ng build --prod --base-href /myapp/
顺便说一句,如果用GitBash构建,它会完全弄乱路径,不要这样做

如果我希望此应用程序在本地windows计算机上运行,并且如果我希望具有指向图像源的可单击(在VSCode中)正确路径,则我必须使用:

index.html

<base href="/">
<base href="./">

在一些组件中,例如:home.component.html

...
<img src="../../assets/data/avatar.png" width=100 />
...
  ...
    <img src="assets/data/avatar.png" width=100 />
  ...
。。。
...
但它希望在部署到Tomcat上时显示图像。我猜文件权限没有问题,因为整个项目是作为'dist'文件夹()的内容上传到Linux服务器的,然后通过TomcatUI管理器部署的。除此之外,所有其他工件都被正确加载

因此,要在Tomcat中显示它,我必须使用:

index.html

<base href="/">
<base href="./">

在一些组件中,例如:home.component.html

...
<img src="../../assets/data/avatar.png" width=100 />
...
  ...
    <img src="assets/data/avatar.png" width=100 />
  ...
。。。
...

已经有一段时间没有部署了,但我不记得Windows和Linux的相对路径应该有什么不同?我哪里出了问题?

一旦构建了项目,请检查
dist
文件夹中的目录结构。您将注意到
资产
目录与
index.html
平行。因此,考虑到这个目录结构,您需要提供资产的路径

因此,在您的模板中,您可以参考您的资产,如下所示-

<img src="./assets/data/avatar.png" width=100 />

构建项目后,检查目录结构的
dist
文件夹。您将注意到
资产
目录与
index.html
平行。因此,考虑到这个目录结构,您需要提供资产的路径

因此,在您的模板中,您可以参考您的资产,如下所示-

<img src="./assets/data/avatar.png" width=100 />