Size: 4326
Comment:
|
Size: 4239
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 25: | Line 25: |
== Maven sample web app == | == Maven sample web app for JBoss AS 7.1.1 == |
Line 27: | Line 27: |
=== web app creation === | === Web application creation === * cd ~ |
Line 34: | Line 35: |
=== Deploy web app on jboss AS 7.1.1 === | === Deploy web application on jboss AS 7.1.1 === |
Line 118: | Line 119: |
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > |
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>
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>