简体   繁体   中英

What is the best way to use GIT for versioning Java Website

I have a git repo installed in my unix for version tracking our Java EE website.

I have currently run into issues not in the usage of git but the way in which I am suppose to use it which is explained below.

I work in a team of 3 developers which contribute to the website development.

Initially when I installed Git in our server I directly created a repo of our webapps directory which contains the actual work files and ran into the foll problems.

1)While committing the changes into the repo one of us would genrally do a git add . and commit it to the repository which would commit not only the files the commiter changed but would also commit the changes of other developers.

When we faced this issue we decided that we needed to create separate non-bare repos for each one of us in the same server in different directories which would house the entire code.The basic work stucture we are following is hown below:

在此处输入图片说明

As shown above in the image we have created a bare repo which would have the website contents pushed by the webapps which in the image is the Work Directory.

The basic workflow here is:

1) Create n number of non-bare repos for each and every developer.

2) Get the entire website work files from pulling from that bare repo

3) After making changes to our own repo push to the bare repo

4) The bare repo being configured with a post-receive hook would actually update the Work Directory.

This setup is working fine but we are facing a lot of issues as shown below:

1) Each developer having his own contetnts in a separate directory is not able to test the code before pushing it to the bare repo which would update the Work Directory- Coz of these steps even for say one jsp file change I end up doing 20 commits until it starts working properly without bugs since we have tomcat pointing to only the original work directory.

This has become the most troubleseme issue here.

This strategy has solved the issue of conflicts which was there before but created even a greater issue regarding testing the code.

How can we improve this scenario where using GIT in out project seems benefitial.

Can anyone suggest any ways for improving the same.

Maybe a strategy like this might work? I've used a similar strategy before with a small team and it worked well for us:

  • Each developer creates a branch before making any changes.
  • Developer does some work and commits to their branch
  • If possible, developers run tomcat (or jetty, or whatever) against their own directory to test. Maven makes this really easy.
  • Before pushing, developers rebase their branches against master
  • Developers push their branch to bare repo
  • Then you (or whoever is in charge of final approval), merges the branch into master. If the developers rebase correctly, this should be a simple fast forward merge.

Updated with some ideas about how each developer might run webapp:

There are a few ways I can think of to accomplish the 3rd bullet point above:

  • Use a single installation of tomcat. Create multiple contexts, one for each developer.

    For example, for developer1, create a context file named dev1.xml under tomcat_home/conf/catalina/localhost with something similar to:

    ?xml version="1.0" encoding="UTF-8"?> Context path="/dev1" docBase="/home/developer1/wars/your-webapp-1.0.war" unpackWAR="false"/>

    (note I removed the first '<' so xml will appear in the post)

  • Use jetty to run the war using command line, something like:

    java -jar jetty-runner.jar your-webapp-1.0.war

  • Use mechanisms provided by a build tool like ant, or maven to run and test the webapp. For example, in maven you can use the jetty-plugin to run the webapp using mvn jetty:run , or even configure it to start a webserver and run tests each time you build the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM