1

My maven webapp has the following structure -webapp -dist -errors -WEB-INF

The 'dist' folder has all the angular build files. In pom.xml I am using maven-resources plugin to copy the content of dist to the root of my .war

When I am running the application in Tomcat. localhost:8080 loads up the angular frontend but if I try to access localhost:8080/assets/xyz.json it loads the app again..probably bcs the server doesn't find the file.

What's wierd is if I try localhost:8080/dist , the app loads fine and localhost:8080/dist/assets/xyz.json loads fine.

I am trying to understand what might be the problem. Does Tomcat not use the .war to serve locally? There is no /dist in the generated .war but in the project's deployed resources I can see -dist -webapp ..

Please help me out if anyone has the idea of what might be the reason here. Also how is localhost:8080 loading the rest of the app but /assets is not working? There is no index.html file in the root of the deployed resources folder..its all inside dist

1 Answers1

1

You can copy the content (all sub directories) from dist to root in your maven webapp (with help of your deployment script).

Or you configure your maven (dist as 'root')

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <warSourceDirectory>webapp/dist</warSourceDirectory>
    </configuration>
</plugin>

Check your index.html: There should be a tag like this: < base href="/" />

In your build script the base href should have the same value:

ng build --prod --base-href /

A second thing: The ajax call against your json should have an relative url like this:

this.http.get<Xxx>('assets/xyz.json');

I hope it helps you.

Marc
  • 1,836
  • 1
  • 10
  • 14
  • Thanks, I believe copying the contents to the root of the webapp folder is the right way to do it. Is there any plugin or some other way to automate this? The war I generate has the content in its root and I am using maven-resources plugin for that. Is there a plugin to do the same for webapp folder? Though I am still confused how is the app loading currently (load index.html), but not able to access relative /assets folder. Yes I am using base href "/" – user8597012 May 21 '20 at 19:37