Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Friday, October 25, 2013

Maven Setup & Eclipse

Method 1:

You can find Maven plugin URLs at below URL

In my case I have selected below URL to install Maven plugin in my eclipse[Helios]
http://download.eclipse.org/technology/m2e/releases/1.3/1.3.0.20130129-0926














Configure Maven project to Dynamic Web Project by default it will not work on server in eclipse. We need to config manually. 









Method 2:
  1. Introduction and Setting up
  2. Understanding Archetypes and pom.xml
  3. Adding a Dependency
  4. A Web Application Using Maven
  5. Introduction to Plugins with the Maven Compiler Plugin
  6. Using the Jetty Plugin
  7. Eclipse Plugin for Maven and Maven Plugin for Eclipse
  8. Creating a Maven Project in Eclipse

Sunday, October 6, 2013

09 - Creating a Maven Project in Eclipse



We'll use the Eclipse plugin m2eclipse to download an archetype to create a project in Eclipse. We'll also run custom commands (goals) like running Jetty, all within Eclipse.
New->other->maven project->next->filter(webapp)->select j23ee 4 -> Group Id(org.yash.javajadhav) -> Artifact Id : mywebapp ->version : 1.0-SNAPShot->finish.
Open pom.xml and remove maven-complie-plugin plugin and jetty plugin
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groudId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
                <scanIntervalSeconds>5</scanIntervalSeconds> -> It checks for every 5 sec either any change in jsp or class files.
</configuration>
</plugin>
</plugins>
</build>

Now right click on pom.xml -> run as -> maven package (it is equal to mvn package command)
Right click on pom.xml-> runas -> maven build… -> Goals : jetty run -> run
Open browser-> http://localhost:8080/mywebapp/

08 - Eclipse Plugin for Maven and Maven Plugin for Eclipse



More plugins! We'll use the Maven's Eclipse plugin to get our Maven project into the Eclipse IDE. We'll also download and install the m2eclipse plugin of Eclipse to bring Maven functionality into the Eclipse GUI.
mvn eclipse:eclipse now we can see .settings and .project files
Open you eclipse import->Existing project->Browser the root directory->finish
In some cases you might an exclamatory (!) mark, it is due to unbound classpath variable (missing of jar path).  Here we just right click -> properties -> java build path -> Libraries ->configure M2_Repo
Add variable->configure variable->new->M2_REPO= provide repository path (c:/user/yash/.m2/repository)->ok

Install maven plugin in eclipse
Help-> install new software -> work with(All available sites)-> search for maven->click Maven integration for eclipse->next->next->finish(restart eclipse)

07 - Using the Jetty Plugin



There are some Maven plugins that are full Servlet containers. We'll look at an example: the Jetty plugin, and we'll see how it makes developing web applications easier.
Open pom.xml
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groudId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
                <scanIntervalSeconds>5</scanIntervalSeconds> -> It checks for every 5 sec either any change in jsp or class files.
</configuration>
</plugin>
</plugins>
</build>

Now run below command
mvn jetty:run -> First maven download the plugin and then run

http://localhost:8080/mywebapp -> access this browser you will see “Hello World”

06 - Introduction to Plugins with the Maven Compiler Plugin



Here you see a plug in called maven compiler which has configuration tags source and target. Source is nothing but JVM version and target for runtime is 1.4. This is there because while choosing archetype jee verion 1.4, if I choosen jee 5 then this would be 1.5.
Default source is 1.4, if you don’t  fine in pom.xml maven takes 1.4 as default.
If you are trying to write Generic method of 1.5 then you need to change the source to 1.5.
Here what I will try to run some Generic method of 1.5 which generates error.
Let create a class in src eg. MyClass.java
public class MyClass{
                public static void main(String[] args){
                List<String> stringList = new ArrayList<String>();
                }
}

mvn compile -> here is the error “generics not supported in source 1.4”. It is coming from pom.xml, now change the source to 1.5 and target to 1.5. now compile again mvn compile.
Now remove the source plugin and compile again it works fine.