Size: 604
Comment:
|
Size: 7647
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 18: | Line 18: |
Package: [[attachment: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 {{{#!highlight xml <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> <version>2.2.1.GA</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>6.0</version> <scope>provided</scope> </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 {{{#!highlight java package org.allowed.bitarus; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; @Path("/testSvc") public class TestService { @GET @Path("/{param}") public Response getMsg(@PathParam("param") String msg) { String out = String.format("testSvc returns %s", msg); return Response.status(200).entity(out).build(); } } }}} File src/main/java/org/allowed/bitarus/Servletx.java http://localhost:8080/WebApp/servletxxx {{{#!highlight java package org.allowed.bitarus; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Servletx extends HttpServlet{ public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<html><head><title>Hello World!</title></head>"); out.println("<body><h1>Hello World!</h1></body></html>"); } } }}} === Configure web app === File src/main/webapp/WEB-INF/web.xml {{{#!highlight xml <web-app> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/rest</param-value> </context-param> <servlet> <servlet-name>resteasy-servlet</servlet-name> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>resteasy-servlet</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>Servletx</servlet-name> <servlet-class>org.allowed.bitarus.Servletx</servlet-class> </servlet> <servlet-mapping> <servlet-name>Servletx</servlet-name> <url-pattern>/servletxxx</url-pattern> </servlet-mapping> </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 {{{#!highlight xml <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"> <modelVersion>4.0.0</modelVersion> <groupId>org.allowed.bitarus</groupId> <artifactId>test2</artifactId> <version>0.0.1</version> <packaging>ejb</packaging> <build> <sourceDirectory>ejbModule</sourceDirectory> <resources> <resource> <directory>ejbModule</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <plugins> <plugin> <artifactId>maven-ejb-plugin</artifactId> <version>2.3</version> <configuration> <ejbVersion>3.0</ejbVersion> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <!-- EJB 3.0 --> <groupId>javax.ejb</groupId> <artifactId>ejb-api</artifactId> <version>3.0</version> </dependency> <dependency> <!--jax ws web servies --> <groupId>sun-jaxws</groupId> <artifactId>jsr181-api</artifactId> <version>1.0</version> </dependency> </dependencies> </project> }}} Source code files {{{#!highlight java }}} {{{#!highlight java }}} {{{#!highlight java }}} Build EJB JAR with maven * mvn clean compile package |
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
- admin 12345678
- Manage deployments
- Add content
- Choose file ~/WebApp/target/WebApp.war
- next, save
- enable , confirm
Add REST and servlet support
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
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
Build EJB JAR with maven
- mvn clean compile package