MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 17 as of 2014-05-27 13:44:49
  • Java
  • ApacheMaven

Apache Maven

Maven is a software project management and comprehension tool. Based on the concept of a Project Object Model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

Requires Java.

Slackbuild

  • su
  • cd /tmp
  • wget http://slackbuilds.org/slackbuilds/14.0/development/apache-maven.tar.gz

  • tar xvzf apache-maven.tar.gz
  • cd apache-maven
  • wget http://archive.apache.org/dist/maven/binaries/apache-maven-3.0.4-bin.tar.gz

  • ./apache-maven.SlackBuild

  • installpkg /tmp/apache-maven-3.0.4-noarch-1_SBo.tgz

Package: apache-maven-3.0.4-noarch-1_SBo.tgz

User settings

You can specify your user configuration in ${user.home}/.m2/settings.xml. The default location of your local repository is ${user.home}/.m2/repository/.

Maven sample web app for JBoss AS 7.1.1

Web application creation

  • cd ~
  • mvn archetype:generate -DgroupId=org.allowed.bitarus -DartifactId=WebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

  • cd WebApp

  • mvn clean
  • mvn compile
  • mvn package

Deploy web application on jboss AS 7.1.1

  • /opt/jboss-as-7.1.1.Final/bin/standalone.sh
  • http://localhost:9990

  • admin 12345678
  • Manage deployments
  • Add content
  • Choose file ~/WebApp/target/WebApp.war
  • next, save
  • enable , confirm
  • http://localhost:8080/WebApp/

Add REST and servlet support

  • url http://localhost:8080/WebApp/rest/testSvc/paramx

Add dependencies to pom.xml, jboss AS 7.1.1 JAX-RS

   1 <dependency>
   2     <groupId>org.jboss.resteasy</groupId>
   3     <artifactId>resteasy-jaxrs</artifactId>
   4     <version>2.2.1.GA</version>
   5     <scope>provided</scope>
   6 </dependency>
   7 <dependency>
   8     <groupId>javax</groupId>
   9     <artifactId>javaee-web-api</artifactId>
  10     <version>6.0</version>
  11     <scope>provided</scope>
  12 </dependency>

In JBoss 5.1.0 comment the scope provided for resteasy, to add to WEB-INF folder the required libraries for resteasy.

Create source code for REST service and servlet

File src/main/java/org/allowed/bitarus/TestService.java

URL http://localhost:8080/WebApp/rest/testSvc/asddddd

   1 package org.allowed.bitarus;
   2 
   3 import javax.ws.rs.GET;
   4 import javax.ws.rs.Path;
   5 import javax.ws.rs.PathParam;
   6 import javax.ws.rs.core.Response;
   7 
   8 @Path("/testSvc")
   9 public class TestService {
  10 
  11     @GET
  12     @Path("/{param}")
  13     public Response getMsg(@PathParam("param") String msg) {
  14         String out = String.format("testSvc returns %s", msg);
  15         return Response.status(200).entity(out).build();
  16     }
  17 
  18 }

File src/main/java/org/allowed/bitarus/Servletx.java

http://localhost:8080/WebApp/servletxxx

   1 package org.allowed.bitarus;
   2 
   3 import javax.servlet.*;
   4 import javax.servlet.http.*;
   5 import java.io.*;
   6 
   7 public class Servletx extends HttpServlet{
   8     public void service(HttpServletRequest req, HttpServletResponse res) throws IOException
   9     {
  10         res.setContentType("text/html");
  11         PrintWriter out = res.getWriter();
  12         out.println("<html><head><title>Hello World!</title></head>");
  13         out.println("<body><h1>Hello World!</h1></body></html>");
  14     }
  15 }

Configure web app

File src/main/webapp/WEB-INF/web.xml

   1 <web-app>
   2   <display-name>Archetype Created Web Application</display-name>
   3   <context-param>
   4     <param-name>resteasy.scan</param-name>
   5     <param-value>true</param-value>
   6   </context-param>
   7  
   8   <context-param>
   9     <param-name>resteasy.servlet.mapping.prefix</param-name>
  10     <param-value>/rest</param-value>
  11   </context-param>
  12 
  13   <servlet>
  14     <servlet-name>resteasy-servlet</servlet-name>
  15     <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
  16   </servlet>
  17   <servlet-mapping>
  18     <servlet-name>resteasy-servlet</servlet-name>
  19     <url-pattern>/rest/*</url-pattern>
  20   </servlet-mapping>
  21 
  22   <servlet>
  23     <servlet-name>Servletx</servlet-name>
  24     <servlet-class>org.allowed.bitarus.Servletx</servlet-class>
  25   </servlet>
  26   <servlet-mapping>
  27     <servlet-name>Servletx</servlet-name>
  28     <url-pattern>/servletxxx</url-pattern> 
  29   </servlet-mapping>
  30 </web-app>

Dependencies scopes on pom.xml

compile

compile is the default scope; all dependencies are compile-scoped if a scope is not supplied. compile dependencies are available in all classpaths, and they are packaged.

provided

provided dependencies are used when you expect the JDK or a container to provide them.

Eclipse plugin

Install on Eclipse 3.8.2

  • Choose Help menu
  • Install new software
  • Name: M2Eclipse

  • Location: http://download.eclipse.org/technology/m2e/releases

  • Maven Integration For Eclipse
  • Select all
  • next
  • next
  • I accept
  • Finish

Import existing project

  • Java perspective
  • Import
  • Maven
  • Existing Maven project
  • next
  • root folder
  • next
  • finish

Maven sample enterprise app

  • cd /tmp
  • mvn archetype:generate -DgroupId=org.allowed.bitarus -DartifactId=EnterpriseApp -DarchetypeArtifactId=org.jboss.spec.archetypes.jboss-javaee6-ear-webapp -DinteractiveMode=false

  • cd EnterpriseApp/
  • Edit pom.xml and comment site module
  • mvn clean
  • mvn compile
  • mvn package # /tmp/EnterpriseApp/EnterpriseApp-ear/target/EnterpriseApp.ear
  • Deploy the EnterpriseApp.ear with http://localhost:9990

  • Open http://localhost:8080/EnterpriseApp/index.jsf

Maven sample ejb JEE5

  • cd /tmp
  • mvn archetype:generate -DgroupId=org.allowed.bitarus -DartifactId=EjbJEE5 -DarchetypeArtifactId=org.codehaus.mojo.archetypes.ejb-jee5 -DinteractiveMode=false

  • cd EnterpriseApp/
  • Edit pom.xml and comment site module
  • mvn clean
  • mvn compile
  • mvn package # /tmp/EnterpriseApp/EnterpriseApp-ear/target/EnterpriseApp.ear

POM EJB 3.0 + JAX-WS

For JBoss 5.0. Source code Java below folder ejbModule. Create source folder in Eclipse named ejbModule.

pom.xml

   1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   2   <modelVersion>4.0.0</modelVersion>
   3   <groupId>org.allowed.bitarus</groupId>
   4   <artifactId>test2</artifactId>
   5   <version>0.0.1</version>
   6   <packaging>ejb</packaging>
   7   
   8   <build>
   9     <sourceDirectory>ejbModule</sourceDirectory>
  10     <resources>
  11       <resource>
  12         <directory>ejbModule</directory>
  13         <excludes>
  14           <exclude>**/*.java</exclude>
  15         </excludes>
  16       </resource>
  17     </resources>
  18     <plugins>
  19       <plugin>
  20         <artifactId>maven-ejb-plugin</artifactId>
  21         <version>2.3</version>
  22         <configuration>
  23           <ejbVersion>3.0</ejbVersion>
  24         </configuration>
  25       </plugin>
  26     </plugins>
  27   </build>
  28   
  29   <dependencies>
  30     <dependency>
  31         <!-- EJB 3.0 -->
  32         <groupId>javax.ejb</groupId>
  33         <artifactId>ejb-api</artifactId>
  34         <version>3.0</version>
  35     </dependency>
  36     <dependency>
  37         <!--jax ws web servies -->
  38         <groupId>sun-jaxws</groupId>
  39         <artifactId>jsr181-api</artifactId>
  40         <version>1.0</version>
  41     </dependency>
  42   </dependencies>
  43 </project>

Source code files

   1 

   1 

   1 

Build EJB JAR with maven

  • mvn clean compile package
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01