15

I've developed a Spring maven rest api for my project. For the client side, I'm using Angular2 with typescript. As new to Angular, referred angular website for the development, using npm and lite-server.

Now I need to make these two separate projects into a single project, by integrating the html,js,css files into my maven project, to deploy it in Tomcat server.

Project structure

Client side

Project
|__ app
      |_ all app files
|__ node_modules
|__ typings
|__ index.html
|__ package.json
|__ style.css
|__ systemjs.config.js
|__ tsconfig.json
|__ typings.json

Server side

Project
|__ src/main
        |__ java
        |__ resources
        |__ webapp
                 |__index.html
|__ pom.xml

All similar posts/blogs, i found suggest to update pom.xml with node etc. But what i need is,

  • Compile the angular-typescript project to js files.
  • Produce a set of fully functional html,js,css files.
  • Copy them to server webapp folder or whereever they must be.
  • Running Spring maven project in Tomcat must display my client side index page
  • Client must work (communicating with rest api) same way when they were two separate projects

How this can be done?

Run this command, npm run build, in angular project root folder to create a dist folder, containing production ready client side files. But got this error

missing script build

.

1

1 Answer 1

21

At last used angular-cli. ng build --prod creates a production ready build. Copied index.html and .js files under project folder in tomcat webapps (Or under Webcontent in eclipse).

Edited index.html as <base href = "."> and it worked fine

Sign up to request clarification or add additional context in comments.

8 Comments

@MendonAshwini If question and answer helped you, please up vote them, so that it will reach more people quickly ( not only for me ;) )
Sure. I missed to upvote the question. Answer I upvoted already
I am trying to deploy my angular cli project via a similar method to an Oracle WebLogic server (I'm actually using the grunt-war npm to build a war to deploy). I've adjusted the <base href = "."> as you show above. After deploying the war file, I can hit the app from the url: [weblogic IP]:[port]/[appname] and if I just click on links the app works fine. However if I ever refresh a page or try to navigate to a specific page via a url, I get a 404 error. Any idea what that's about?
@ZackDeRose I've not much experience in this. Better you please ask a new question, someone in SO, who have a better understanding, can help you. Good luck!
@RamanujanR appreciate you looking out. I resolved the issue by building via the command ng build --base-href /[app-name]/ and wrapping that up in a war file (via grunt). I also had to adjust my RouterModule import in my app.module.ts file to: RouterModule.forRoot(appRoutues, {useHase: true}) This will add a /#/ between the app name and the path, but as I understand, that's pretty much unavoidable if you're putting an angular app out on a Tomcat or WebLogic.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.