How to use Maven for agile development

1

Category:

How to Use Maven on Your Project

Created by Susan Davis. Last edited by Jessamyn Smith, 3 years ago.Install MavenObtain Maven (version2.0.5) from file://Iwdbackup/iwd_apps/Maven or http://maven.apache.org/download.html Unzip maven-2.0.5-bin.zip to the directory you wish to install Maven. Add the bin directory to your path, eg. SET PATH="C:\Program Files\maven-2.0.5\bin";%PATH% Make sure that JAVA_HOME is set to the location of your JDK. Run mvn --version to verify that it is correctly installed. Modify maven's settings.xml to reference internal Intelliware repositories.Overwrite a standard settings.xml in /conf with this one: settings.xml. Use Maven to create an applicationMaven provides an archetype mechanism to allow you to quickly create different kinds of projects. Some common archetypes are:
maven-archetype-webapp for web applications maven-archetype-simple - quick start archetype to generate simple project maven-archetype-site archetype - to create a site docummentation for your project For a more comprehensive list see Codehaus's Archetypes ListYou can also create your own archetypes. To do so, refer to maven's Guide to Creating Archetypes
Example: Creating a web applicationRun a following command in the directory where you want your project to be created:
mvn archetype:create -DgroupId=ca.intelliware -DartifactId=simpleWebApp -DarchetypeArtifactId=maven-archetype-webapp
The result is: simpleWebApp+-- pom.xml+-- src/ +-- main/ +-- resources/ +-- webapp/ +-- index.jsp +-- WEB-INF/ +-- web.xml
The first time you run this (or any other) command, Maven will need to download all the plugins and related dependencies it needs to fulfill the command. Therefore it might take some time when you run it for the first time. Maven uses the concept of repositories to manage your dependencies. When you download maven and install it, it creates your local repository. When we say "maven downloads dependencies" we mean it gets them from the maven repo and copies them to your local repository.
Example: Creating a simple application:mvn archetype:create -DgroupId=ca.intelliware -DartifactId=simpleWebApp
Making sense of pom.xmlWhen you've used maven to create your project, notice that it created a pom.xml file in your main project directory. This file (arcronym of Project Object Model) contains every important piece of information about your project and is essentially one-stop-shopping for finding anything related to your project. To learn more about it, visit Introduction to the POM.
For an example of a POM file that includes configuration for the Intelliware Maven infrastructure see: Sample POM for Intelliware.
Maven on a rollNow that we have our project created, we can add in our code and utilize a whole new bag of Maven tricks.
Note all Maven commands must be run in the same directory as the project's pom.xml file.
mvn test: Runs the JUnit tests for the application. mvn package: Creates a .war file from our project. mvn install: Adds our project .war to the repository for use as a dependency if needed. mvn site: Generates the project website. mvn clean: Cleans the output created in the target directory. mvn eclipse:eclipse: Generates an Eclipse project file. Where, "test", "package", and "install" are Maven lifecycle phases, and "site" and "eclipse" are Maven plugins.
Deploy to WebServer and RunThe Quick and Easy Way
We can now deploy the application to the Jetty webserver and run it by entering:
mvn org.mortbay.jetty:maven-jetty-plugin:runWe can then hit the page and see our application in action: http://localhost:8080/simpleWebApp/
Defining the Webserver in your pom.xml
Specify the plugin for your web server in the project's pom.xml (the example below is for Jetty):
org.mortbay.jetty maven-jetty-pluginWe can then startup the web app by running: mvn jetty:run

Auto Deployment of Eclipse WAR fiel to Tomcat using ANT Scripts

0

Category:

Auto Deployment of Eclipse WAR fiel to Tomcat using ANT Scripts
Eclipse allows us to run the application and then export the application to a standard WAR file. But then someone has to manually do the following steps :
Export the project to a WAR file using Eclipse Interface
Copy the WAR file from the location created to the Tomcat webapps folder
Here is a better alternative and a solution to the question :
Create an ANT script that will look at the Eclipse Project structure and build the WAR file and copy over the WAR file to the destination (Tomcat WebApps folder)
Here is the ANT script:




















Save the above code into a file and name it “build.xml”. Place the build.xml into the root folder of your eclipse project. For example, if “c:\projects” is my eclipse workspace and “SanFrancisco” is the name of my project then all the files related to the project will be under “c:\projects\SanFrancisco”.
You can run the ant command inside the projects root folder either using any ANT tool installed or if you have ArcGIS Java ADF installed then there is a customized ANT tool executable available for use.
Here is the usage:
1. Create the WAR file and deploy it to tomcat
"c:\program files\arcgis\java\tools\ant\build\arcgisant" deploy
2. Just create the WAR file
"c:\program files\arcgis\java\tools\ant\build\arcgisant" create
3. Just copy over the WAR file to deploy location
"c:\program files\arcgis\java\tools\ant\build\arcgisant" copy
4. Unpack the WAR file to see the contents
"c:\program files\arcgis\java\tools\ant\build\arcgisant" unpack

Unpacking and Repacking EAR and WAR files

0

Category: , ,

Unpacking and Repacking EAR and WAR files
The procedures discussed in this chapter are specific to the Microsoft Windows platform.
To unpack the .ear or .war file:
1. Open the command prompt, and navigate to the folder that contains the EAR or WAR file.
2. Create a folder named "[Temporary EAR location]” or "[Temporary WAR location]”.
3. Go up one level to the folder that contains the EAR or WAR file.
4. Select the EAR or WAR file you want to unpack, right-click the file, select the Open with option,
and select WinZip to unpack the EAR or WAR file to the temporary location "[Temporary EAR
location]” or "[Temporary WAR location]”.
Note: You can choose to configure your computer to consider EAR or WAR files as ZIP files,
by performing the following steps:
1. Go to the Control Panel.
2. Double-click Folder Options.
The Folder Options dialog box is displayed.
3. Click the File Types tab.
4. Navigate to the EAR or WAR extension in the Registered file types list.
5. Click Change.
The Open With dialog box is displayed.
6. Select WinZip in the Programs list.
7. Click OK.
8. Click Apply.
9. Click OK.
To repack the .ear or .war file:
1. Access one folder level above "[Temporary WAR location]”.
2. Select the "[Temporary WAR location]”.
3. Right-click the folder, select WinZip, and choose the Add to Zip option.
4. In the Add to archive field of the Add dialog box, specify the name of the .ear or .war file you
are repacking.
5. Click Add.