A Developer's Diary

Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Jan 12, 2013

Maven - Copying artifacts to specific folder

Above is the directory structure of web application generated using maven. Use maven-dependency-plugin for copying artifacts to desired folder under WEB-INF directory

Read more ...

Jan 3, 2013

Deploying web applications using maven command line

Maven comes up with a powerful list of features and plugins for rapid application development, deployment and testing.

While developing web applications, the need is always felt to deploy, undeploy and redeploy applications using the command line. For apache tomcat, maven comes up with a tomcat-maven-plugin which facilitates the same.

1. Follow the steps mentioned in the post for creating a simple web application.
2. Add the below lines in your pom.xml. This will download the tomcat-maven-plugin jar in your local maven repository.

<build>
    <finalName>webapp</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <username>admin</username>
                    <password>admin</password>
                </configuration>
            </plugin>
    
        </plugins>
    </pluginManagement>
  </build>

Read more ...

Dec 13, 2012

Configuring build path in Eclipse for Maven projects

The .classpath file generated after executing maven mvn eclipse:eclipse looks like the following

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
    <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

When the same project is imported into eclipse, the build path is configured accordingly. The parameter including=**/*.java specifies that only java files are included in the class path.
In the example above, no other files are included in the class path and will throw FileNotFoundException if referenced

Read more ...

Setting up Spring Development Environment using Maven

The step by step guide for creating a java project using Maven and configuring it for Spring Framework

#1. Setup a simple Java project using Maven
Use mvn archetype:generate command for creating a sample java project. When prompted hit enter to select the version as 1.0-SNAPSHOT and package as com.examples.spring

mvn archetype:generate -DgroupId=com.examples.spring -DartifactId=HelloSpring -DarchetypeArtifactId=maven-archetype-quickstart

Read more ...

Importing a maven project in eclipse

You can import a maven project to eclipse without installing the maven plugin by following these simple steps

Generate Eclipse specific files
Eclipse looks for .classpath and .project files in your project. Use the maven command mvn eclipse:eclipse to generate files for your project

Importing the Project in Eclipse

1. Start Eclipse. Goto File and select Import...
2. Select Existing Projects into Workspace. Click Next
3. When asked to select root directory, browse and point it to the project folder you want to import
4. Click Finish and your project is successfully imported into eclipse

Note: Make sure that M2_REPO variable is set to Maven Local Repository in eclipse

Read more ...

May 19, 2012

A simple java web application in minutes

You can set up your simple java web application in no time using maven. The application can be downloaded from maven's site.

Maven comes up with a single line command to create Hello World web application for you. The value to the argument archetypeArtifactId identifies that the project to be created is of type web application. In case you are running this command for the first time, it will take some time for the maven to download the dependent plugins first and then create the sample application

Create Web Application Project
mvn archetype:create -DgroupId=com.simple.web -DartifactId=webapp -DarchetypeArtifactId=maven-archetype-webapp
Your sample application is created and ready to be packaged and deployed

Read more ...

May 18, 2012

Maven cheat sheet for the beginners

Maven is a build automation tool used by the java developers. Some of the commands which I use on daily basis are:

Create a Java Project
mvn archetype:create -DgroupId=com.devfaqs.project -DartifactId=MyProject
Above is a single line command to create hello world java project. The command creates the project in a well defined directory structure along with the provision to write and execute junit test cases for the project created

Read more ...