= 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: [[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
org.jboss.resteasy
resteasy-jaxrs
2.2.1.GA
provided
javax
javaee-web-api
6.0
provided
}}}
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("
Hello World!");
out.println("Hello World!
");
}
}
}}}
=== Configure web app ===
File src/main/webapp/WEB-INF/web.xml
{{{#!highlight xml
Archetype Created Web Application
resteasy.scan
true
resteasy.servlet.mapping.prefix
/rest
resteasy-servlet
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
resteasy-servlet
/rest/*
Servletx
org.allowed.bitarus.Servletx
Servletx
/servletxxx
}}}
== 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 + JBoss 5.1.0 ==
For JBoss 5.0. Source code Java below folder ejbModule.
Create source folder in Eclipse named ejbModule.
pom.xml
{{{#!highlight xml
4.0.0
org.allowed.bitarus
test2
0.0.1
ejb
ejbModule
ejbModule
**/*.java
maven-ejb-plugin
2.3
3.0
javax.ejb
ejb-api
3.0
sun-jaxws
jsr181-api
1.0
javaee
javaee-api
5
}}}
Source code files in ejbModule/org/allowed/bitarus
{{{#!highlight java
//WSTest.java
package org.allowed.bitarus;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.InitialContext;
/**
* Session Bean implementation class WSTest
*/
@Stateless
@WebService
// http://localhost:8080/test2-0.0.1/WSTest?wsdl
public class WSTest implements WSTestRemote, WSTestLocal {
private static final String QUERY1 = "SELECT distinct table_name FROM user_tables";
private static final String JNDI_DATASOURCE = "java:OracleDS";
public WSTest() {
}
@WebMethod
public String helloWorld() {
return "Hello world";
}
@WebMethod
public String[] checkDB() {
ArrayList list = new ArrayList();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Context ctx = new InitialContext();
conn = ((javax.sql.DataSource) ctx.lookup(WSTest.JNDI_DATASOURCE)).getConnection();
ps = conn.prepareStatement(WSTest.QUERY1);
rs = ps.executeQuery();
while (rs.next()) {
list.add(rs.getString(1));
}
} catch (Exception e) {
list.add(e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
String[] r = new String[list.size()];
list.toArray(r);
return r;
}
}
}}}
{{{#!highlight java
//WSTestLocal.java
package org.allowed.bitarus;
import javax.ejb.Local;
@Local
public interface WSTestLocal {
}
}}}
{{{#!highlight java
//WSTestRemote.java
package org.allowed.bitarus;
import javax.ejb.Remote;
@Remote
public interface WSTestRemote {
}
}}}
Build EJB JAR with maven
* mvn clean compile package
In http://localhost:8080/admin-console/ at link EJB 3.x Application (EJB JAR), add resource test2-0.0.1.jar.
In JBoss 5.1.0 copy the following libraries from the JBOSS_HOME/client directory to the JBOSS_HOME/lib/endorsed directory,
so that the JAX-WS 2.0 apis supported by JBossWS are used:
* jbossws-native-saaj.jar
* jbossws-native-jaxrpc.jar
* jbossws-native-jaxws.jar
* jbossws-native-jaxws-ext.jar
Check deployed EJB with http://localhost:8080/test2-0.0.1/WSTest?wsdl
File structure:
{{{
vitor@darkstar$tree .
.
|-- ejbModule
| `-- org
| `-- allowed
| `-- bitarus
| |-- WSTest.java
| |-- WSTestLocal.java
| `-- WSTestRemote.java
|-- pom.xml
`-- target
|-- classes
| `-- org
| `-- allowed
| `-- bitarus
| |-- WSTest.class
| |-- WSTestLocal.class
| `-- WSTestRemote.class
|-- maven-archiver
| `-- pom.properties
|-- surefire
`-- test2-0.0.1.jar
11 directories, 9 files
}}}
=== Oracle datasource for JBoss 5 ===
Copy to C:\timwe\appsvr\jboss-5.1.0.GA\server\default\deploy\oracle-ds.xml
Copy ojdbc6.jar to <...>\jboss-5.1.0.GA\server\default\lib
{{{#!highlight xml
OracleDS
jdbc:oracle:thin:@localhost:1521:xe
oracle.jdbc.driver.OracleDriver
SYSTEM
jboss
org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker
Oracle9i
}}}