Web App (Spring, Angular, Grunt, Maven, Tomcat) running both grunt and tomcat servers

前端 未结 2 440
日久生厌
日久生厌 2021-02-03 13:51

OK so I\'ve been reading several of the other stack questions and trying to piece this together without much luck. Basically my approach is that I currently have one project wit

2条回答
  •  一整个雨季
    2021-02-03 14:38

    from your question i digged up only two questions

    1. How to do continuous development with grunt/bower + tomcat
    2. How to deploy for production

    1 - Continuous development

    The solution i have chosen for that - since you already use api to communicate client <-> server- is to separate completely the two projects.

    So what does it mean? for me is to have two different repositories. One for client, One for Server one this way you get few benefits:

    • Split the work on the projects (front-end/server-side)
    • Easier to maintain
    • In case you want to support "API only" For an example, mobile application, and etc..

    But - How do they communicate while developing?

    This is a good question: One solution is to run two server on localhost in parallel, i.e mvn clean tomcat:run -P yourprofile; grunt server

    But - I'll get cross domain if I try to access server-side from client-side from different port? You are right. And here you get the help of grunt and its plugin. grab a copy of grunt-connect-proxy

    What is nice about this plugin that it acts as a middleware between grunt server and tomcat server so you ask grunt server for the API but actually grunt is asking tomcat server to answer on that (behind the scenes of course)

    2 - Deploy for production

    I guess this is a matter of personal preference question. I find the war file extremely big to do upload again and again (even if are able to share lib between all of your tomcat app). The solution I came up with is to do deploy over git.

    OK, but I have one big war file. How can I do that?

    For me I use a deploy script I wrote in bash. This is what it does:

    1. Tag the current source
    2. Run mvn clean package war:exploded -P your-prod-profile (this will run test and integration test as well)
    3. With the above command you get all your complied project's file in one place, instead of one big war file.
    4. Copy all those files (and inner paths) into outside folder (I use another repository for maintenance deployment over git. So basically I have 3 repositories. One for server source, one for client source, and one for server binaries.)
    5. Before doing 4 make sure to delete all files and folders (besides .git stuff) from it
    6. After 4 do "git add -A"
    7. "git commit -a -m 'new production version X"
    8. You can mark some tags before and after for allowing easy way of recovering the last code if there was a big bug in the new production
    9. Run remote command on server to a.) stop server, b.) pull the last changes from the binary repository, c.) run server again.
    10. For me what I did is a symbolic link between tomcat app to an outside folder (the binary repository) so

    Hope this will give you some directions,

    Bests, Oak

提交回复
热议问题