Reputation: 43
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
Upvotes: 1
Views: 1197
Reputation: 1896
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.
Upvotes: 1