• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Learning Maven

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am completely new to Maven. I am pretty excited to learn Maven. I have installed Eclipse Java EE IDE for Web Developers. Version: Juno Service Release 2.

I also installed Maven Integration for Eclipse WTP in Eclipse.

I downloaded the latest version of Maven (3.0.5) from: http://maven.apache.org/download.cgi

Now I created a Maven Project : File -> New -> Other -> Maven -> Maven Project -> Next -> Which group ID and artifact ID do I choose ?

How do I make a war file?

Suppose I want to try out a simple web project and would like to make a war file for it and deploy in JBoss server.

How to proceed. Feeling very confused.

Not getting help from anywhere

Please do Help and Guide me to learn Maven !!!

Sid.
 
Ranch Hand
Posts: 199
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Now I created a Maven Project : File -> New -> Other -> Maven -> Maven Project -> Next -> Which group ID and artifact ID do I choose ?



Eclipse -> File -> New -> Other -> Maven -> Maven Project -> Next ->
Then you could select and archetype, set filter to 'web' and select 'maven-archetype-webapp', click next.
Now set group id "my-webapp", artifact id "my-webapp-test" and package "my.webapp.test".
You are done, browse your maven webapp project.

Click your project / run / run as / click maven build / click on new launch configuration (icon with a sheet +) / select your maven project as base directory and set goal as package / run
Now you have your project packaged as a war in the target directory.


Best regards
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carles Gasques wrote:Hi,

Now I created a Maven Project : File -> New -> Other -> Maven -> Maven Project -> Next -> Which group ID and artifact ID do I choose ?



Eclipse -> File -> New -> Other -> Maven -> Maven Project -> Next ->
Then you could select and archetype, set filter to 'web' and select 'maven-archetype-webapp', click next.
Now set group id "my-webapp", artifact id "my-webapp-test" and package "my.webapp.test".
You are done, browse your maven webapp project.

Click your project / run / run as / click maven build / click on new launch configuration (icon with a sheet +) / select your maven project as base directory and set goal as package / run
Now you have your project packaged as a war in the target directory.


Best regards



Thanks Charles,

I rt. clicked on my project. selected Run As -> Maven build...

I am not getting any new lunch configuration.... Also how to select my maven project as base directory ..... set goal as package / run. ???

Also I need to add dependency and plugins as well..... For example dependency for servlets-apis jar files, jstls, etc..

Please consider me as a layman in maven and explain in detail.

Thanks
Sid.

 
Carles Gasques
Ranch Hand
Posts: 199
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,

Click your project / run / run as /run configurations / click maven build / click on new launch configuration (icon with a sheet +) / select your maven project as base directory and set goal as "package" / click run button
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other possibility is to ignore the various archetypes and instead go with a simple Maven project (the top checkbox) on the first page New Maven Project dialog, then on the next page choose "war" in the packaging dropdown. That will give you a basic WAR project.

What you use for GroupId and ProjectId is up to you. You really need to examine how others have set these up. The groupId usually matches the basic package name for the classes in the project. For example, you can find groupIds that start with "org.apache", "org.jboss", etc.

For the projectId, use the name that you want to give to your WAR file. That name will also be the name used for the project directory in the Eclipse workspace.

It might help if you went through a simple Maven tutorial for building a web application. You can find on in chapter 4 of Better Builds with Maven (http://www.maestrodev.com/support/)
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Johnson wrote:The other possibility is to ignore the various archetypes and instead go with a simple Maven project (the top checkbox) on the first page New Maven Project dialog, then on the next page choose "war" in the packaging dropdown. That will give you a basic WAR project.

What you use for GroupId and ProjectId is up to you. You really need to examine how others have set these up. The groupId usually matches the basic package name for the classes in the project. For example, you can find groupIds that start with "org.apache", "org.jboss", etc.

For the projectId, use the name that you want to give to your WAR file. That name will also be the name used for the project directory in the Eclipse workspace.

It might help if you went through a simple Maven tutorial for building a web application. You can find on in chapter 4 of Better Builds with Maven (http://www.maestrodev.com/support/)



Hi,

I managed to make a war file successfully through Maven.

What I am doing is for a new maven project:

File -> New -> Other -> Maven-> Maven Project -> (Next)

Chose Filter as : webapp

It shows as:

Group Id: org.apache.maven.archetypes
Artifact Id: maven-archetype-webapp
Version: RELEASE.

Clicked on Next

Entered the Artifact Id and GroupId and clicked on Finish.


I am basically trying to learn Servlet Concepts by running the practical examples. I am using JBoss 7.1 as my Application server.

Following is my pom.xml



My Queries:

1) If I am creating servlets then I would need to compile Java source files to build .class files. How do we do this in maven ? Would .class files automatically become a part of the war file? What I need to modify in my pom.xml file ?

2) I want the generated war file to deploy automatically in the Jboss folder. Currently I have to copy the war file from its generated location to the JBoss folder (Jboss->standalone-> deployments)

For generating a war file I write click on pom.xml -> Maven build ... -> Goals - package -> Click on Apply and Click on Run

Please guide and help me ....

Thanks and Regards,
Sid.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Yes. Place your servlet and related Java sources in src/main/java. Maven will automatically include the compiled class files in WEB-INF/classes in the WAR file. You do not need to do anything special in the POM to get this behavior.

2) There is a Maven plugin for JBoss AS 7 that will do this for you. See http://docs.jboss.org/jbossas/7/plugins/maven/7.4.Final/
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Johnson wrote:1) Yes. Place your servlet and related Java sources in src/main/java. Maven will automatically include the compiled class files in WEB-INF/classes in the WAR file. You do not need to do anything special in the POM to get this behavior.

2) There is a Maven plugin for JBoss AS 7 that will do this for you. See http://docs.jboss.org/jbossas/7/plugins/maven/7.4.Final/



Hi Peter,

1) I am having source folder as : src/main/resources and not src/main/java

Are we trying to say that the java source files would compile only when they are kept in the folder src/main/java and not any other folder such as src/main/resources?

In the dialog box for selecting an archetype I am giving the filter as : webapp The GroupId, ArtifactId and Version which I choose is as follows:

Group Id: org.apache.maven.archetypes
ArtifactId: maven-archetype-webapp
Version: RELEASE

Am I missing something OR doing something wrong ?

Kindly advise

Thanks and Regards,
Siddharth
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is correct. Java source files need to be in src/main/java. Other files that you expect to be in the classpath, such as properties files or the log4j.xml file, should be in src/main/resources. That the difference between a source file (which is processed by the Maven Compiler Plugin, and resource files, which are processed by the Maven Resources Plugin.

What books have you read on Maven? Have you looked at:
Better Builds with Maven (http://www.maestrodev.com/support/) - a little dated but still contains good tutorials to get you started (has a comlete tutorial on building web apps)
Maven, the Complete Reference (http://www.sonatype.com/resources/books) - I reference this one so much I have it pinned to my Nitro PDF jump list
Both are free PDF downloads and recommended reading.
 
author
Posts: 82
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because mastery of Maven is essential to effectively using Hudson, we cover Maven extensively in our book, "Hudson Continuous Integration in Practice". Here is a little excerpt from Chapter 5: Hudson and Automated Testing.


TIP
Maven is an extreme example of the principle of “inversion of control.” The key to success with Maven is to work with it, not against it. This is best achieved by avoiding trying to change how Maven does things. Rather, it is best to find out the way Maven intends to do the sort of thing you want and then provide input to that process.

All of the action in Maven happens on top of the backbone of the build lifecycle. All of the work done by Maven during a build is done by plugins executing at specific phases during the build lifecycle. Each specific thing that a plugin does is called a “goal.” Plugins typically declare in which lifecycle phases their goals are designed to execute. There are actually three lifecycles that are used in Maven, called clean, default, and site. Every invocation of mvn will use at least one of these three lifecycles. When analyzing its command-line arguments, Maven determines which of the three lifecycles to run and the end phase for each one, based on the order in which the arguments are specified. The clean and site lifecycles deal with running the clean and site goals. Clean resets the project to its nonbuilt state, usually just deleting the target directory. Site generates reports, such as code coverage and unit test results. The default lifecycle is the most interesting and is where most of the work is done by Maven and its many plugins. Hudson jobs that invoke Maven will usually have cause to use all of these different lifecycles in one way or another.
Each of the three lifecycles consists of several different phases, each with a name and purpose and executed in sequence by Maven. Maven always executes at least one of the three lifecycles, and when it does, it always executes them from the start phase until the user-specified end phase. You can think of the execution of the lifecycle phases as a journey on a non-express train from the starting station through multiple stations. When traveling on a such a train from the starting station, you can get off at any station, but no stations can be skipped.



Ed
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ed Burns wrote:Because mastery of Maven is essential to effectively using Hudson, we cover Maven extensively in our book, "Hudson Continuous Integration in Practice". Here is a little excerpt from Chapter 5: Hudson and Automated Testing.


Only if you are using Maven . If you are using Hudson to run Ant scripts, mastery of Ant is essential.

And yes, I know this is a nit, but had to bring it up anyway. The Maven coverage in the book is great.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have Maven and Jenkins well integrated at work. In fact, every project is a Maven project, thus every Jenkins job runs Maven - even the numerous jobs and projects that have nothing to do with Java. And every artifact we build goes into Nexus, even the non-Java artifacts.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic