Monday, March 21, 2011

Eclipse PDT - auto deploy webapp to htdocs (webroot)

I've been using EclipsePDT (Eclipse PHP Development Tools project) for quite a bit now. One thing that this Eclipse distribution lacks is an 'auto deploy' feature which will automatically copy your web app to your http servers webroot (htdocs folder). Most people will suggest to make your Eclipse workspace reside in the webroot folder to combat this. I hate this idea so I utilized ANT to auto copy my web files to my web root everytime I saved.

This technique utilizes the addition of a custom builder to your web project. First, create a file 'build.properties' in the root of your eclipse project.

In your build.properties file place the following lines...

apache.htdocs.dir=C:/Program Files (x86)/Zend/Apache2/htdocs
web.root.dir=my_webproject
full.deploy.path=${apache.htdocs.dir}/${web.root.dir}

Replace the apache.htdocs.dir to your webroot folder. Next change web.root.dir to your web project name (as it reflects in eclipse).

Now, create a file build.xml and place this in the root of your eclipse project. Paste the following into this file




 

 

     

     

         
             
         

     

 


Next, you need to tell eclipse that you have a custom builder that you want to run every time you save a file in your project. To do this, right click your project and goto "Properties". In the properties wizard, click on 'Builders'. Click the 'New...' button to create a new builder. Select the option 'Ant Builder'. A configuration wizard will now appear. The buildfile field, click the button 'Browse Workspace...' and select the build.xml file we created.

That completes the task. Edit a file in your project and save it. You will notice some ant output in your console showing the copy that is done to copy your webapp to your webroot.

10 comments:

  1. Awesome solution! Saved me a ton a time. Thank you!

    ReplyDelete
  2. Thank you Matthew... you just helped me keep my job!

    ReplyDelete
  3. Hi, when I click the 'New...' button in Properties > Builders, no 'Ant Builder' option avalaible, only Program.

    Win 7 Home Premium SP1
    Zend Eclipse PDT 3.0.2 w/Eclipse Indigo
    - Plugin: Ant Build Tool Core 3.2.302.v20120110-1739
    Zend Server CE

    Thanks in advance

    ReplyDelete
    Replies
    1. Do you have the "Ant Launching Support" plugin installed? Mine is v1.0.100.v20110506 . Your Ant Build Tool Core plugin version is the same one I am using.

      Delete
  4. No, I don't. Only:

    Ant Build Tool Core 3.2.302.v20120110-1739
    Apache Ant 1.8.2.v20120109-1030

    I tried to install "Ant Launching Support" plugin but couldn't find it. Site supposedly having it according a post I saw, says "No repository found at http://www.eclipse.org/eclipse/ant/
    If I use Work with: --All available Sites-- and type Ant in the filter, nothing is listed

    Any idea where to find that plugin?

    ReplyDelete
    Replies
    1. The only thing I can suggest without installing Zend myself and investigating is to download a standard copy of eclipse from here http://www.eclipse.org/downloads/ . Extract it, go into the plugins folder and copy the org.eclipse.ant.launching jars you find to your zend eclipse plugins folder.

      I can't guarantee this to work without trying it myself and this is NOT the recommended way of installing plugins by eclipse.

      You may want to make a copy of your zend installation before you do this just in case.

      Delete
  5. This doesn't work with docker wtf?

    ReplyDelete
  6. "mcafee is an antivirus software providers that secure your computer for virus , worms ,trojens and other mailcious program .it provides full range of
    security product like antivirus , firewall etc .you have to do mcafee antivirus download "

    ReplyDelete