Friday, October 09, 2015

Deploy java web application in Azure Web App

Deploy java web application in Azure Web App


     1.   Create an azure webApp with Apache Tomcat (Here I created with name of     horizonsjava)
    2. After creating WebApp, goto DASHBOARD under quick glance, Reset the credentials




 3.      Open File Explore and enter the ftp url (provide the FTP host name)



Give the credentials of Deployment ftp  and click on “Log on”

 
   4.    Navigation to site/wwwroot/bin/apache-tomcat-8.0.26/


   5.   Now we need enable the users, Open tomcat-users.xml “/conf/tomcat-users.xml”

Now remove the comment surrounded the roles and user tag(<!-- -->)
And add two lines highlighted and save it


 6.   Restart the azure webApp

   7.   Now login to Visual Studio Online account
Push your Java app to VSO using Eclipse
Go to builds and create vnext build wi
th following activities
a.      Add a build step Ant.
b.      Ant build file: give the server path of build.xml file
c.       Target(s):war
(Note: To generate a war we need to add peace of code in build.xml file)

a.      Add Publish build Artifacts
b.      Contents: **/*.war
c.       Artifact Name: default it is “drops” if required any name you can change it.
  


a.      Add Publish build PowerShell
b.      Script filename: browse the version control path of .ps1 file
Create a power shell script and Check in to the VSO
The power shell script is

$ftp_uri = ftp://waws-prod-sg1-009.ftp.azurewebsites.windows.net/site/wwwroot/bin/apache-tomcat-8.0.26/webapps/
$user = <<FTP User>>
$pass = <<FTP Password>>
$path = $args[0]
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 
    foreach($item in Get-ChildItem -recurse $path){
        $relpath = [system.io.path]::GetFullPath($item.FullName).SubString([system.io.path]::GetFullPath($path).Length + 1)
        if ($item.Attributes -eq "Directory"){
            try{
                Write-Host Creating $item.Name
                $makeDirectory = [System.Net.WebRequest]::Create($ftp_uri+$relpath);
                $makeDirectory.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
                $makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory;
                $makeDirectory.GetResponse();
            }catch [Net.WebException] {
                Write-Host $item.Name probably exists ...
            }
            continue;
        }
        "Uploading $item..."
        $uri = New-Object System.Uri($ftp_uri+$relpath)
        "$relpath"
        $webclient.UploadFile($uri, $item.FullName)
    }
c.       Arguments : $(Agent.BuildDirectory)\Artifacts




8. And save the build


9. Queue the build.



      10. Open browser and enter the http url of your web app,
           My Web app URL is "http:// horizonsjava.azurewebsites.net/Horizons"

Deploying the Java Application on Azure Web App using Release Management


Deploying the Java Application on Azure Web App using Release Management

Download the Dump software’s which we can UN zip and make use of it no need of installation.

1.       Download Apache Ant from below link
2.       Download Java JDK from below link
4.       Download TFS build Extension from below link
5.       Download eclipse from below link
6.   Download Horizons java project from below link

Java Web App configure
1.   Create an azure webApp with Apache Tomcat (Here I created with name of horizonsjava)
         And webApp url is horizonsjava.azurewebsites.net
2.   After creating WebApp got DASHBOARD à quick glance
Reset the credentials


3.   Open File Explore and enter the ftp url
Here give the FTP host name
  


 4.      Give the credentials of Deployment ftp  and click on “Log on”



5.   Go to folder navigation of "site/wwwroot/bin/apache-tomcat-8.0.26/"
   6.     Now enable the users Open tomcat-users.xml “/conf/tomcat-users.xml”

7.   Now remove the comment surrounded the roles and user tag(<!-- -->)
And add two lines highlighted and save it
8.   Restart the azure webApp
  
7. Steps for Setup
 1. Un zip the apache ant folder and copy to C drive
 2. Un zip the apache tomcat folder and copy to C drive or if it is exe file install it
 

 3. Un zip the java folder and copy to C drive or if it is exe install it


 4. Go to “My Computer” Right click and select “Properties

5.      Click on “Advance System Settings


6.      Go to “Advance Tab” and the click on “Environment Variables” 


7.      Under “system variables” section click on “New


8.      Set the Environment variables for Ant, Java
For ant give the variables and click on ok


Again click on new For java give the variables and click on ok



9.       Now go to “path variable” and click on edit


Append the variables at the end of the “path variable” like
Note: give the “; “ properly in variable values.
%JAVA_HOME%\bin;JAVA_HOME%\lib;%ANT_HOME%\bin;%ANT_HOME%\lib;


8.   Now install the TFS build Extension on build server
Note: if you are using TFS 2015 build this step is not required.

Click on next

 

Select “I Agree” and click on next


Click on next

 



 Click on next


Installation is completed click on close.



 9.   Setup project in eclipse
Note:(If it is existing eclipse project goto file->import->select “existing project to work space” Give the path of the project and click on finish)
Open eclipse
   

It will prompt for work space give any path and click on ok
Now go to file->new->dynamic web project


Give the project name and click on next



Click on next


Check the option Generate web.xml and click on finish



You will see the project


Open the “Horizons project” which you downloaded from above link copy all the content in it


Past it in the eclipse project which you created horizons->webcontent (under web content folder past the files)




Generate the build.xml file using export option
Right click on  project click on export


Select ant and click on next


Select the project and click on finish


You will see the build.xml file in project

Modify the build.xml to generate a war file past the below code just above the </project> tag

<target name="war" description="Bundles the application as a WAR file" depends="clean, build">
           <mkdir dir="WebContent/WEB-INF/classes"/>
         <copy includeemptydirs="false" todir="WebContent/WEB-INF/classes">
          <fileset dir="build/classes">
                            <include name="**/*.class"/>
                            </fileset>
                    </copy>
               <war destfile="DeploymentPackage/Horizons.war"
                        basedir="WebContent"
                        needxmlfile="false">
                    </war>
                </target>



10.   Install Team explore every where
1.       Open Eclipse.
2.       On the Help menu, choose Install New Software.
The Install dialog box appears.


The install wizard looks slightly different for different versions of Eclipse.
3.       Choose Add.
The Add Repository dialog box appears.


4.       In Name, enter TFS Plugin for Eclipse.
5.       In Location, enter http://dl.microsoft.com/eclipse/tfs, and then choose OK.
6.       In the list of features in the Install dialog box, select the check box that corresponds to Team Explorer Everywhere, and then choose Next two times.
Note: uncheck Contact all update sites during install to find required software 


7.     Accept the Microsoft Software License Terms, and then choose Finish.


8.     Restart Eclipse when prompted click on restart.
 11.   Open team explore everywhere.
       Window ->show view ->other


And select Team explorer click on ok


After team explorer window will open add the TFS server
     


12.   Share the project which is created in the eclipse


Select the team foundation server and click next


Select the team project to share the web project and click next


Click on finish



After finishing the sharing go to team explore -> pending changes
We can see the pending changes of the project shared click on check-in


It will ask for conformation to check in click on yes


We can see the changeset created



13.   Go to build and create the new build definition
 
Give the name of the build


In trigger select manual build 
In source settings give the TFS path for the project
 
In build defaults
  

In project File click on create(here we can see the warning)

Select the ant click on next


We generated build.xml in previous steps
Select the build.xml and click on next


Here in drop down select default which will take the version of the java and ant we configured
Note: (if we want to run this project on different versions in drop down select the source control refer the link "http://msdnsolutions.blogspot.in/2015/07/java-to-build-in-different-versions.html”)
Click on finish


After finishing warning will be gone it will create a .TFSproj file in version control you can check it.
Click on ok

Now modify the TFSBuild.proj file
In Target tag give “war”


14.   Now trigger the build


 Click on queue


You can see the build have passed


15.   For release management add the ReleaseUpgradeTemplate.xaml to that team project and check in it.
(Download build template form here ReleaseUpgradeTemplate.xml)
If it is RM 2015 download the template from here ReleaseUpgradeTemplate.xaml
 
Goto team explore in visual studio -> builds
Select the horizonss build which we created
Right click and select edit build definition


Goto process click on new


Select the template which have checked-in


Now select the template which we add from drop down
In Release Build option select “True”
In configurations to Release select “Any CPU and Release” And save the build


Now goto release management client create a release path.



Create components
In path to package give “Horizons/DeploymentPackage” it is my folder name where build.xml file will create looking in to the file.
Note: base on your drop location structure where the .war located


In deployment from drop down select xcopy Deployer and then click on save


Now go to release templates double click on template created now


On components right click and add the component we created



Drag and drop the server where the tomcat is there in my case VSALM server


Create a temp folder on rm agent “C:\Drops\HorizonsTemp”
Drag and drop component we created and command line
Installation path: Give the temp folder which you created

Create a power shell script
The power shell script is

$ftp_uri = ftp://waws-prod-sg1-009.ftp.azurewebsites.windows.net/site/wwwroot/bin/apache-tomcat-8.0.26/webapps/
$user = <<FTP User>>
$pass = <<FTP Password>>
$path = $args[0]
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 
    foreach($item in Get-ChildItem -recurse $path){
        $relpath = [system.io.path]::GetFullPath($item.FullName).SubString([system.io.path]::GetFullPath($path).Length + 1)
        if ($item.Attributes -eq "Directory"){
            try{
                Write-Host Creating $item.Name
                $makeDirectory = [System.Net.WebRequest]::Create($ftp_uri+$relpath);
                $makeDirectory.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
                $makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory;
                $makeDirectory.GetResponse();
            }catch [Net.WebException] {
                Write-Host $item.Name probably exists ...
            }
            continue;
        }
        "Uploading $item..."
        $uri = New-Object System.Uri($ftp_uri+$relpath)
        "$relpath"
        $webclient.UploadFile($uri, $item.FullName)
    }
 FilePath: give the path of powershell script.
 Notepowershell script there on rm agent
Argument: give the temp folder you created


Now go to the Property and linked the build



Now go to eclipse modify the index.html page and save the file and go to pending changes and check in.


Now trigger the build
Go and check in RM client the project has been released


Now go to browser URL http:// horizonsjava.azurewebsites.net/Horizons
And click on manage app and then you can see the projects list
Here we can see the projects horizons
Click on horizons


Here we can see the change which we modified in index.html file