Contents
-
Apache Maven
- Lifecycles and phases
- Slackbuild
- User settings
- Maven sample web app for JBoss AS 7.1.1
- Dependencies scopes on pom.xml
- Eclipse plugin
- Maven sample enterprise app
- Maven sample EJB JEE5
- POM EJB 3.0 + JAX-WS + JBoss 5.1.0
- Assembly plugin
- Standalone app - Fat JAR
- Install JAR local repository
- Maven skip tests
- Ant run plugin - copy
- Download javadoc
- Install raw maven in Slackware
- Check dependencies for artifact
- Copy dependencies
- Standalone app - FAT Jar - Java 1.7
- Standalone app/service - FAT Jar - Java 17
- Attach debugger to mvn test
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.
Lifecycles and phases
Clean Lifecycle
- pre-clean: execute processes needed prior to the actual project cleaning
- clean: remove all files generated by the previous build
- post-clean: execute processes needed to finalize the project cleaning
Default Lifecycle
- validate: validate the project is correct and all necessary information is available.
- initialize: initialize build state, e.g. set properties or create directories.
- generate-sources: generate any source code for inclusion in compilation.
- process-sources: process the source code, for example to filter any values.
- generate-resources: generate resources for inclusion in the package.
- process-resources: copy and process the resources into the destination directory, ready for packaging.
- compile: compile the source code of the project.
- process-classes: post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.
- generate-test-sources: generate any test source code for inclusion in compilation.
- process-test-sources: process the test source code, for example to filter any values.
- generate-test-resources: create resources for testing.
- process-test-resources: copy and process the resources into the test destination directory.
- test-compile: compile the test source code into the test destination directory
- process-test-classes: post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes.
- test: run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
- prepare-package: perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package.
- package: take the compiled code and package it in its distributable format, such as a JAR.
- pre-integration-test: perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
- integration-test: process and deploy the package if necessary into an environment where integration tests can be run.
- post-integration-test: perform actions required after integration tests have been executed. This may including cleaning up the environment.
- verify: run any checks to verify the package is valid and meets quality criteria.
- install: install the package into the local repository, for use as a dependency in other projects locally.
- deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
Site Lifecycle
- pre-site: execute processes needed prior to the actual project site generation
- site: generate the project's site documentation
- post-site: execute processes needed to finalize the site generation, and to prepare for site deployment
- site-deploy: deploy the generated site documentation to the specified web server
Slackbuild
1 su
2 cd /tmp
3 wget https://slackbuilds.org/slackbuilds/14.2/development/apache-maven.tar.gz
4 tar xvzf apache-maven.tar.gz
5 cd apache-maven
6 wget http://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
7 ./apache-maven.SlackBuild
8 installpkg /tmp/apache-maven-3.8.1-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
Sample WebApp file with source code to use MySQL data source:WebApp.zip
Sample WebAppJersey2, with dependencies for Jersey2 and JSON, to be deployed on Tomcat 7:WebAppJersey2.zip
Deploy web application on jboss AS 7.1.1
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
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 }
src/main/java/org/allowed/bitarus/Servletx.java
http://localhost:8080/WebApp/servletxxx
1 // File src/main/java/org/allowed/bitarus/Servletx.java
2 // References EJB in JBoss5. Test to see EJB invocation from Tomcat
3 package org.allowed.bitarus;
4
5 import javax.servlet.*;
6 import javax.servlet.http.*;
7 import java.io.*;
8
9 import java.security.Security;
10 import java.util.Properties;
11 import javax.naming.Context;
12 import javax.naming.InitialContext;
13 import org.allowed.bitarus.IWSTest;
14
15 public class Servletx extends HttpServlet{
16 public void service(HttpServletRequest req, HttpServletResponse res) throws IOException
17 {
18 res.setContentType("text/html");
19 PrintWriter out = res.getWriter();
20 String text="";
21 try{
22 Properties env = new Properties();
23 env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
24 env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
25 env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
26 InitialContext context = new InitialContext(env);
27 IWSTest test = (IWSTest) context.lookup("WSTest/remote");
28 text=test.helloWorld();
29 }
30 catch(Exception ex){
31 }
32 out.println("<html><head><title>Hello World!</title></head>");
33 out.println(String.format("<body><h1>Hello World! %s </h1></body></html>",text));
34 }
35 }
Dependency for JAR that has IWSTest interface that WSTest EJB implements:
Configure web app
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
1 cd /tmp
2 mvn archetype:generate -DgroupId=org.allowed.bitarus -DartifactId=EnterpriseApp -DarchetypeArtifactId=org.jboss.spec.archetypes.jboss-javaee6-ear-webapp -DinteractiveMode=false
3 cd EnterpriseApp/
4 # Edit pom.xml and comment site module
5 mvn clean
6 mvn compile
7 mvn package # /tmp/EnterpriseApp/EnterpriseApp-ear/target/EnterpriseApp.ear
8 # Deploy the EnterpriseApp.ear with http://localhost:9990 (JBoss/Wildfly web console)
9 # Open http://localhost:8080/EnterpriseApp/index.jsf
10
Maven sample EJB JEE5
1 cd /tmp
2 mvn archetype:generate -DgroupId=org.allowed.bitarus -DartifactId=EjbJEE5 -DarchetypeArtifactId=org.codehaus.mojo.archetypes.ejb-jee5 -DinteractiveMode=false
3 cd EnterpriseApp/
4 # Edit pom.xml and comment site module
5 mvn clean
6 mvn compile
7 mvn package # /tmp/EnterpriseApp/EnterpriseApp-ear/target/EnterpriseApp.ear
8
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
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
43 <dependency>
44 <groupId>javaee</groupId>
45 <artifactId>javaee-api</artifactId>
46 <version>5</version>
47 </dependency>
48
49 </dependencies>
50 </project>
ejbModule/org/allowed/bitarus/WSTest.java
1 package org.allowed.bitarus;
2
3 import java.sql.Connection;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.util.ArrayList;
8
9 import javax.ejb.Stateless;
10 import javax.jws.WebMethod;
11 import javax.jws.WebService;
12 import javax.naming.Context;
13 import javax.naming.InitialContext;
14
15 /**
16 * Session Bean implementation class WSTest
17 */
18 @Stateless
19 @WebService
20 // http://localhost:8080/test2-0.0.1/WSTest?wsdl
21 public class WSTest implements WSTestRemote, WSTestLocal {
22 private static final String QUERY1 = "SELECT distinct table_name FROM user_tables";
23 private static final String JNDI_DATASOURCE = "java:OracleDS";
24 // private static final String QUERY1 = "select table_name from information_schema.tables;";
25 // private static final String JNDI_DATASOURCE = "java:/MysqlDS";
26
27 public WSTest() {
28 }
29
30 @WebMethod
31 public String helloWorld() {
32 return "Hello world";
33 }
34
35 @WebMethod
36 public String[] checkDB() {
37 ArrayList<String> list = new ArrayList<String>();
38
39 Connection conn = null;
40 PreparedStatement ps = null;
41 ResultSet rs = null;
42
43 try {
44 Context ctx = new InitialContext();
45 conn = ((javax.sql.DataSource) ctx.lookup(WSTest.JNDI_DATASOURCE)).getConnection();
46 ps = conn.prepareStatement(WSTest.QUERY1);
47 rs = ps.executeQuery();
48 while (rs.next()) {
49 list.add(rs.getString(1));
50 }
51 } catch (Exception e) {
52 list.add(e.getMessage());
53 } finally {
54 if (rs != null) {
55 try {
56 rs.close();
57 } catch (SQLException e) {
58 e.printStackTrace();
59 }
60 }
61
62 if (ps != null) {
63 try {
64 ps.close();
65 } catch (SQLException e) {
66 e.printStackTrace();
67 }
68 }
69 if (conn != null) {
70 try {
71 conn.close();
72 } catch (SQLException e) {
73 e.printStackTrace();
74 }
75 }
76 }
77
78 String[] r = new String[list.size()];
79 list.toArray(r);
80 return r;
81 }
82 }
ejbModule/org/allowed/bitarus/WSTestLocal.java
ejbModule/org/allowed/bitarus/WSTestRemote.java
ejbModule/org/allowed/bitarus/IWSTest.java
Build EJB JAR with maven
1 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
Project structure:
1 .
2 |-- ejbModule
3 | `-- org
4 | `-- allowed
5 | `-- bitarus
6 | |-- IWSTest.java
7 | |-- WSTest.java
8 | |-- WSTestLocal.java
9 | `-- WSTestRemote.java
10 |-- pom.xml
11 `-- target
12 |-- classes
13 | `-- org
14 | `-- allowed
15 | `-- bitarus
16 | |-- IWSTest.class
17 | |-- WSTest.class
18 | |-- WSTestLocal.class
19 | `-- WSTestRemote.class
20 |-- maven-archiver
21 | `-- pom.properties
22 |-- surefire
23 `-- test2-0.0.1.jar
Oracle datasource for JBoss 5
Copy to <...>\jboss-5.1.0.GA\server\default\deploy\oracle-ds.xml
Copy ojdbc6.jar to <...>\jboss-5.1.0.GA\server\default\lib
1 <?xml version="1.0" encoding="UTF-8"?>
2 <datasources>
3 <!-- copy ojdbc6.jar to <...>\jboss-5.1.0.GA\server\default\lib -->
4 <local-tx-datasource>
5 <jndi-name>OracleDS</jndi-name>
6 <connection-url>jdbc:oracle:thin:@localhost:1521:xe</connection-url>
7 <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
8 <user-name>SYSTEM</user-name>
9 <password>jboss</password>
10 <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
11 <metadata>
12 <type-mapping>Oracle9i</type-mapping>
13 </metadata>
14 </local-tx-datasource>
15 </datasources>
MySQL datasource for JBoss 5
Copy to <...>\jboss-5.1.0.GA\server\default\deploy\mysql-ds.xml
Copy mysql-connector-java-5.1.30-bin.jar to <...>\jboss-5.1.0.GA\server\default\lib
1 <?xml version="1.0" encoding="UTF-8"?>
2 <datasources>
3 <local-tx-datasource>
4 <jndi-name>MysqlDS</jndi-name>
5 <connection-url>jdbc:mysql://localhost:3306/mysql</connection-url>
6 <driver-class>com.mysql.jdbc.Driver</driver-class>
7 <user-name>root</user-name>
8 <password>12345678</password>
9 <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
10 <metadata>
11 <type-mapping>mySQL</type-mapping>
12 </metadata>
13 </local-tx-datasource>
14 </datasources>
Assembly plugin
The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.
http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
<project> <!-- ... --> <build> <!-- ... --> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </project>
Standalone app - Fat JAR
pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
3 http://maven.apache.org/maven-v4_0_0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>com.example</groupId>
6 <artifactId>artifactX</artifactId>
7 <packaging>jar</packaging>
8 <version>0.0.1</version>
9 <name>artifactX</name>
10 <url>http://maven.apache.org</url>
11 <build>
12 <plugins>
13 <plugin>
14 <artifactId>maven-assembly-plugin</artifactId>
15 <version>2.4</version>
16 <configuration>
17 <descriptorRefs>
18 <descriptorRef>jar-with-dependencies</descriptorRef>
19 </descriptorRefs>
20 <archive>
21 <manifest>
22 <mainClass>com.example.Main</mainClass>
23 </manifest>
24 </archive>
25 </configuration>
26 <executions>
27 <execution>
28 <id>make-assembly</id>
29 <phase>package</phase>
30 <goals>
31 <goal>single</goal>
32 </goals>
33 </execution>
34 </executions>
35 </plugin>
36 </plugins>
37 </build>
38 <dependencies>
39 <dependency>
40 <groupId>com.google.code.gson</groupId>
41 <artifactId>gson</artifactId>
42 <version>2.3</version>
43 </dependency>
44 <dependency>
45 <groupId>mysql</groupId>
46 <artifactId>mysql-connector-java</artifactId>
47 <version>5.1.31</version>
48 <scope>compile</scope>
49 </dependency>
50 <dependency>
51 <groupId>org.slf4j</groupId>
52 <artifactId>slf4j-api</artifactId>
53 <version>1.7.7</version>
54 </dependency>
55 <dependency>
56 <groupId>org.slf4j</groupId>
57 <artifactId>slf4j-simple</artifactId>
58 <version>1.7.7</version>
59 </dependency>
60 </dependencies>
61 </project>
Init script CentOS/Fedora
- In debian /etc/init.d/progx
1 #!/bin/sh
2 # chkconfig: 345 99 99
3 # description: Starts and stops the progx process
4 USER=userx
5 PROG=progx
6 PIDFILE="/tmp/progx.pid"
7 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin"
8 LOG="/tmp/progx.log"
9 JAVA="/usr/java/jdk1.6.0_26/bin/java"
10 JARFILE="/home/userx/progx-0.0.1-jar-with-dependencies.jar"
11
12 start(){
13 echo "Start called $PROG with user $USER"
14 su - $USER -c "$JAVA -jar $JARFILE " &
15 /bin/sleep 2
16 PID=`ps uax| grep java | grep $PROG | grep $USER | awk '{print $2}'`
17 echo "Program $PROG running with PID: $PID"
18 echo "$PID" > $PIDFILE
19 }
20
21 status(){
22 PID=`cat $PIDFILE`
23 echo "Running $PROG with PID: $PID"
24 }
25
26 stop(){
27 echo "Stop called for $PROG"
28 PID=`cat $PIDFILE`
29 echo "PID to kill $PROG $PID"
30 kill -9 $PID
31 rm $PIDFILE
32 }
33
34 # switch
35 case "$1" in
36 start)
37 start
38 ;;
39 status)
40 status
41 ;;
42 stop)
43 stop
44 ;;
45 restart)
46 stop
47 start
48 ;;
49 *)
50 echo "$PROG start|status|stop|restart"
51 exit 1
52 ;;
53 esac
Install JAR local repository
To install a JAR in the local repository use the following command:
1 mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
1 mvn install:install-file -DgroupId=com.sun -DartifactId=tools -Dversion=1.4.2 -Dpackaging=jar -Dfile=C:\temp\test\tools.jar
Dependency:
<dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.4.2</version> </dependency>
Maven skip tests
http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-test.html
or
1 <project>
2 <!-- [...] -->
3 <build>
4 <plugins>
5 <plugin>
6 <groupId>org.apache.maven.plugins</groupId>
7 <artifactId>maven-surefire-plugin</artifactId>
8 <version>2.18.1</version>
9 <configuration>
10 <skipTests>true</skipTests>
11 </configuration>
12 </plugin>
13 </plugins>
14 </build>
15 <!-- [...] -->
16 </project>
Ant run plugin - copy
The maven-antrun-plugin has only one goal, run.
1 <plugin>
2 <groupId>org.apache.maven.plugins</groupId>
3 <artifactId>maven-antrun-plugin</artifactId>
4 <version>1.8</version>
5 <executions>
6 <execution>
7 <id>copy</id>
8 <phase>install</phase>
9 <goals>
10 <goal>run</goal>
11 </goals>
12 <configuration>
13 <target name="Copy war">
14 <copy file="target/test.war" tofile="C:/Java/apache-tomcat-7.0.57/webapps/test.war" verbose="true" />
15 </target>
16 </configuration>
17 </execution>
18 </executions>
19 </plugin>
Download javadoc
1 mvn clean install dependency:resolve -Dclassifier=javadoc
Install raw maven in Slackware
1 cd ~/Downloads
2 wget http://www-eu.apache.org/dist/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz
3 cp apache-maven-3.5.3-bin.tar.gz /opt/java
4 cd /opt/java
5 tar xvzf apache-maven-3.5.3-bin.tar.gz
6 cd apache-maven-3.5.3/bin/
7 ./mvn
8 PATH=$PATH:/opt/java/jdk1.8.0_162/bin:/opt/java/apache-maven-3.5.3/bin
Check dependencies for artifact
- set artifact in pom.xml file
- run mvn dependency:tree --log-file out.txt
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>check-dep</groupId>
4 <artifactId>check-dep</artifactId>
5 <version>0.0.1</version>
6 <packaging>pom</packaging>
7 <repositories>
8 <repository>
9 <id>android-repo</id>
10 <name>android-repo</name>
11 <url>https://dl.google.com/dl/android/maven2/</url>
12 </repository>
13 <repository>
14 <id>spring-io-plugins-release</id>
15 <name>spring-io-plugins-release</name>
16 <url>https://repo.spring.io/plugins-release/</url>
17 </repository>
18 </repositories>
19 <dependencies>
20 <dependency>
21 <groupId>com.android.tools.build</groupId>
22 <artifactId>gradle</artifactId>
23 <version>2.3.1</version>
24 </dependency>
25 <dependency>
26 <groupId>androidx.annotation</groupId>
27 <artifactId>annotation</artifactId>
28 <version>1.0.0</version>
29 </dependency>
30 <dependency>
31 <groupId>androidx.core</groupId>
32 <artifactId>core</artifactId>
33 <version>1.0.2</version>
34 <type>aar</type>
35 </dependency>
36 <dependency>
37 <groupId>androidx.legacy</groupId>
38 <artifactId>legacy-support-v4</artifactId>
39 <version>1.0.0</version>
40 <type>aar</type>
41 </dependency>
42 <dependency>
43 <groupId>com.google.android.gms</groupId>
44 <artifactId>play-services-analytics</artifactId>
45 <version>11.0.1</version>
46 <type>aar</type>
47 </dependency>
48 <dependency>
49 <groupId>com.google.firebase</groupId>
50 <artifactId>firebase-analytics</artifactId>
51 <version>17.2.3</version>
52 <type>aar</type>
53 </dependency>
54 <dependency>
55 <groupId>com.google.firebase</groupId>
56 <artifactId>firebase-messaging</artifactId>
57 <version>20.1.7</version>
58 <type>aar</type>
59 </dependency>
60 <dependency>
61 <groupId>com.squareup.okhttp3</groupId>
62 <artifactId>okhttp-urlconnection</artifactId>
63 <version>3.10.0</version>
64 </dependency>
65 <dependency>
66 <groupId>me.leolin</groupId>
67 <artifactId>ShortcutBadger</artifactId>
68 <version>1.1.22</version>
69 <type>aar</type>
70 </dependency>
71 <dependency>
72 <groupId>com.android.support</groupId>
73 <artifactId>appcompat-v7</artifactId>
74 <version>23.4.0</version>
75 <type>aar</type>
76 </dependency>
77 </dependencies>
78 </project>
Sample output
[INFO] [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ check-dep --- [INFO] check-dep:check-dep:pom:0.0.1 [INFO] +- com.android.tools.build:gradle:jar:2.3.1:compile [INFO] | \- com.android.tools.build:gradle-core:jar:2.3.1:runtime [INFO] | +- com.android.tools.build:builder:jar:2.3.1:runtime [INFO] | | +- com.android.tools.build:builder-model:jar:2.3.1:runtime [INFO] | | +- com.android.tools.build:builder-test-api:jar:2.3.1:runtime [INFO] | | +- com.android.tools:sdklib:jar:25.3.1:runtime [INFO] | | | +- com.android.tools.layoutlib:layoutlib-api:jar:25.3.1:runtime [INFO] | | | | \- com.intellij:annotations:jar:12.0:runtime [INFO] | | | +- com.android.tools:dvlib:jar:25.3.1:runtime [INFO] | | | +- com.android.tools:repository:jar:25.3.1:runtime [INFO] | | | | \- com.google.jimfs:jimfs:jar:1.1:runtime [INFO] | | | +- com.google.code.gson:gson:jar:2.2.4:runtime [INFO] | | | +- org.apache.commons:commons-compress:jar:1.8.1:runtime [INFO] | | | +- org.apache.httpcomponents:httpclient:jar:4.1.1:runtime [INFO] | | | | +- org.apache.httpcomponents:httpcore:jar:4.1:runtime [INFO] | | | | +- commons-logging:commons-logging:jar:1.1.1:runtime [INFO] | | | | \- commons-codec:commons-codec:jar:1.4:runtime [INFO] | | | \- org.apache.httpcomponents:httpmime:jar:4.1:runtime [INFO] | | +- com.android.tools:sdk-common:jar:25.3.1:runtime [INFO] | | +- com.android.tools:common:jar:25.3.1:runtime [INFO] | | +- com.android.tools.build:manifest-merger:jar:25.3.1:runtime [INFO] | | | \- net.sf.kxml:kxml2:jar:2.3.0:runtime [INFO] | | +- com.android.tools.ddms:ddmlib:jar:25.3.1:runtime [INFO] | | +- com.android.tools.jack:jack-api:jar:0.13.0:runtime [INFO] | | +- com.android.tools.jill:jill-api:jar:0.10.0:runtime [INFO] | | +- com.android.tools.analytics-library:protos:jar:25.3.1:runtime [INFO] | | +- com.android.tools.analytics-library:shared:jar:25.3.1:runtime [INFO] | | +- com.android.tools.analytics-library:tracker:jar:25.3.1:runtime [INFO] | | +- com.squareup:javawriter:jar:2.5.0:runtime [INFO] | | +- org.bouncycastle:bcpkix-jdk15on:jar:1.48:runtime [INFO] | | +- org.bouncycastle:bcprov-jdk15on:jar:1.48:runtime [INFO] | | \- org.ow2.asm:asm-tree:jar:5.0.4:runtime [INFO] | +- com.android.tools.lint:lint:jar:25.3.1:runtime [INFO] | | +- com.android.tools.lint:lint-checks:jar:25.3.1:runtime [INFO] | | | +- com.android.tools.lint:lint-api:jar:25.3.1:runtime [INFO] | | | | +- com.android.tools.external.com-intellij:uast:jar:162.2228.14:runtime [INFO] | | | | \- com.android.tools.external.lombok:lombok-ast:jar:0.2.3:runtime [INFO] | | | \- org.ow2.asm:asm-analysis:jar:5.0.4:runtime [INFO] | | \- org.eclipse.jdt.core.compiler:ecj:jar:4.6.1:runtime [INFO] | +- com.android.tools.build:transform-api:jar:2.0.0-deprecated-use-gradle-api:runtime [INFO] | +- com.android.tools.build:gradle-api:jar:2.3.1:runtime [INFO] | | \- com.google.guava:guava:jar:18.0:runtime [INFO] | +- com.android.databinding:compilerCommon:jar:2.3.1:runtime [INFO] | | +- com.android.databinding:baseLibrary:jar:2.3.1:runtime [INFO] | | +- org.antlr:antlr4:jar:4.5.3:runtime [INFO] | | +- commons-io:commons-io:jar:2.4:runtime [INFO] | | +- com.googlecode.juniversalchardet:juniversalchardet:jar:1.0.3:runtime [INFO] | | \- com.android.tools:annotations:jar:24.5.0:runtime [INFO] | +- org.ow2.asm:asm:jar:5.0.4:runtime [INFO] | +- org.ow2.asm:asm-commons:jar:5.0.4:runtime [INFO] | +- net.sf.proguard:proguard-gradle:jar:5.3.2:runtime [INFO] | | \- net.sf.proguard:proguard-base:jar:5.3.2:runtime [INFO] | +- org.jacoco:org.jacoco.core:jar:0.7.5.201505241946:runtime [INFO] | | \- org.ow2.asm:asm-debug-all:jar:5.0.1:runtime [INFO] | +- org.jacoco:org.jacoco.report:jar:0.7.5.201505241946:runtime [INFO] | +- net.sf.jopt-simple:jopt-simple:jar:4.9:runtime [INFO] | +- com.google.protobuf:protobuf-java:jar:3.0.0:runtime [INFO] | \- org.antlr:antlr:jar:3.5.2:runtime [INFO] | +- org.antlr:antlr-runtime:jar:3.5.2:runtime [INFO] | \- org.antlr:ST4:jar:4.0.8:runtime [INFO] +- androidx.annotation:annotation:jar:1.0.0:compile [INFO] +- androidx.core:core:aar:1.0.2:compile [INFO] | +- androidx.collection:collection:jar:1.0.0:compile [INFO] | +- androidx.lifecycle:lifecycle-runtime:aar:2.0.0:compile [INFO] | | +- androidx.lifecycle:lifecycle-common:jar:2.0.0:compile [INFO] | | \- androidx.arch.core:core-common:jar:2.0.0:compile [INFO] | \- androidx.versionedparcelable:versionedparcelable:aar:1.0.0:compile [INFO] +- androidx.legacy:legacy-support-v4:aar:1.0.0:compile [INFO] | +- androidx.media:media:aar:1.0.0:compile [INFO] | +- androidx.legacy:legacy-support-core-utils:aar:1.0.0:compile [INFO] | | +- androidx.documentfile:documentfile:aar:1.0.0:compile [INFO] | | +- androidx.loader:loader:aar:1.0.0:compile [INFO] | | | \- androidx.lifecycle:lifecycle-livedata:aar:2.0.0:compile [INFO] | | | +- androidx.arch.core:core-runtime:aar:2.0.0:compile [INFO] | | | \- androidx.lifecycle:lifecycle-livedata-core:aar:2.0.0:compile [INFO] | | +- androidx.localbroadcastmanager:localbroadcastmanager:aar:1.0.0:compile [INFO] | | \- androidx.print:print:aar:1.0.0:compile [INFO] | +- androidx.legacy:legacy-support-core-ui:aar:1.0.0:compile [INFO] | | +- androidx.customview:customview:aar:1.0.0:compile [INFO] | | +- androidx.viewpager:viewpager:aar:1.0.0:compile [INFO] | | +- androidx.coordinatorlayout:coordinatorlayout:aar:1.0.0:compile [INFO] | | +- androidx.drawerlayout:drawerlayout:aar:1.0.0:compile [INFO] | | +- androidx.slidingpanelayout:slidingpanelayout:aar:1.0.0:compile [INFO] | | +- androidx.interpolator:interpolator:aar:1.0.0:compile [INFO] | | +- androidx.swiperefreshlayout:swiperefreshlayout:aar:1.0.0:compile [INFO] | | +- androidx.asynclayoutinflater:asynclayoutinflater:aar:1.0.0:compile [INFO] | | \- androidx.cursoradapter:cursoradapter:aar:1.0.0:compile [INFO] | \- androidx.fragment:fragment:aar:1.0.0:compile [INFO] | \- androidx.lifecycle:lifecycle-viewmodel:aar:2.0.0:compile [INFO] +- com.google.android.gms:play-services-analytics:aar:11.0.1:compile [INFO] | +- com.google.android.gms:play-services-analytics-impl:aar:11.0.1:compile (version selected from constraint [11.0.1,11.0.1]) [INFO] | +- com.google.android.gms:play-services-base:aar:11.0.1:compile (version selected from constraint [11.0.1,11.0.1]) [INFO] | | \- com.google.android.gms:play-services-tasks:aar:11.0.1:compile (version selected from constraint [11.0.1,11.0.1]) [INFO] | +- com.google.android.gms:play-services-basement:aar:11.0.1:compile (version selected from constraint [11.0.1,11.0.1]) [INFO] | \- com.google.android.gms:play-services-tagmanager-v4-impl:aar:11.0.1:compile (version selected from constraint [11.0.1,11.0.1]) [INFO] +- com.google.firebase:firebase-analytics:aar:17.2.3:compile [INFO] | +- com.google.android.gms:play-services-measurement:aar:17.2.3:compile [INFO] | | +- com.google.android.gms:play-services-measurement-base:aar:17.2.3:compile (version selected from constraint [17.2.3,17.2.3]) [INFO] | | \- com.google.android.gms:play-services-measurement-impl:aar:17.2.3:compile (version selected from constraint [17.2.3,17.2.3]) [INFO] | | \- com.google.android.gms:play-services-ads-identifier:aar:17.0.0:compile [INFO] | +- com.google.android.gms:play-services-measurement-api:aar:17.2.3:compile [INFO] | | \- com.google.android.gms:play-services-measurement-sdk-api:aar:17.2.3:compile (version selected from constraint [17.2.3,17.2.3]) [INFO] | \- com.google.android.gms:play-services-measurement-sdk:aar:17.2.3:compile [INFO] +- com.google.firebase:firebase-messaging:aar:20.1.7:compile [INFO] | +- com.google.android.datatransport:transport-api:aar:2.2.0:compile [INFO] | +- com.google.android.datatransport:transport-backend-cct:aar:2.2.0:compile [INFO] | +- com.google.android.datatransport:transport-runtime:aar:2.2.0:compile [INFO] | | \- com.google.dagger:dagger:jar:2.24:compile [INFO] | | \- javax.inject:javax.inject:jar:1:compile [INFO] | +- com.google.android.gms:play-services-stats:aar:17.0.0:compile [INFO] | +- com.google.firebase:firebase-common:aar:19.3.0:compile [INFO] | | \- com.google.auto.value:auto-value-annotations:jar:1.6.5:compile [INFO] | +- com.google.firebase:firebase-components:aar:16.0.0:compile [INFO] | +- com.google.firebase:firebase-datatransport:aar:17.0.3:compile [INFO] | +- com.google.firebase:firebase-encoders-json:aar:16.0.0:compile [INFO] | +- com.google.firebase:firebase-iid:aar:20.1.7:compile (version selected from constraint [20.1.7,20.1.7]) [INFO] | | \- com.google.firebase:firebase-iid-interop:aar:17.0.0:compile [INFO] | +- com.google.firebase:firebase-installations:aar:16.3.0:compile [INFO] | +- com.google.firebase:firebase-installations-interop:aar:16.0.0:compile [INFO] | \- com.google.firebase:firebase-measurement-connector:aar:18.0.0:compile [INFO] +- com.squareup.okhttp3:okhttp-urlconnection:jar:3.10.0:compile [INFO] | \- com.squareup.okhttp3:okhttp:jar:3.10.0:compile [INFO] | \- com.squareup.okio:okio:jar:1.14.0:compile [INFO] +- me.leolin:ShortcutBadger:aar:1.1.22:compile [INFO] \- com.android.support:appcompat-v7:aar:23.4.0:compile [INFO] +- com.android.support:animated-vector-drawable:aar:23.4.0:compile [INFO] +- com.android.support:support-v4:aar:23.4.0:compile [INFO] | \- com.android.support:support-annotations:jar:23.4.0:compile [INFO] \- com.android.support:support-vector-drawable:aar:23.4.0:compile [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------
Copy dependencies
Standalone app - FAT Jar - Java 1.7
1 mvn clean install
pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
3 http://maven.apache.org/maven-v4_0_0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>com.example</groupId>
6 <artifactId>artifactX</artifactId>
7 <packaging>jar</packaging>
8 <version>0.0.1</version>
9 <name>artifactX</name>
10 <url>http://maven.apache.org</url>
11 <build>
12 <plugins>
13 <plugin>
14 <artifactId>maven-assembly-plugin</artifactId>
15 <version>2.4</version>
16 <configuration>
17 <descriptorRefs>
18 <descriptorRef>jar-with-dependencies</descriptorRef>
19 </descriptorRefs>
20 <archive>
21 <manifest>
22 <mainClass>hello.Main</mainClass>
23 </manifest>
24 </archive>
25 </configuration>
26 <executions>
27 <execution>
28 <id>make-assembly</id>
29 <phase>package</phase>
30 <goals>
31 <goal>single</goal>
32 </goals>
33 </execution>
34 </executions>
35 </plugin>
36 </plugins>
37 </build>
38 <dependencies>
39 <dependency>
40 <groupId>org.slf4j</groupId>
41 <artifactId>slf4j-api</artifactId>
42 <version>1.7.7</version>
43 </dependency>
44 <dependency>
45 <groupId>org.slf4j</groupId>
46 <artifactId>slf4j-simple</artifactId>
47 <version>1.7.7</version>
48 </dependency>
49 </dependencies>
50 <properties>
51 <maven.compiler.source>1.7</maven.compiler.source>
52 <maven.compiler.target>1.7</maven.compiler.target>
53 </properties>
54 </project>
src/main/java/hello/Main.java
Standalone app/service - FAT Jar - Java 17
1 cd ~
2 mkdir fat-jar-jdk17
3 cd fat-jar-jdk17/
4 mkdir -p src/main/java/hello
5 touch src/main/java/hello/Main.java
6 nano pom.xml
7 nano src/main/java/hello/Main.java
8 mvn clean install
9 jar tf target/artifact-jdk17-0.0.1-jar-with-dependencies.jar
10 ls -lah target/artifact-jdk17-0.0.1-jar-with-dependencies.jar
11 # -rw-r--r-- 1 vagrant vagrant 76K May 26 18:00 target/artifact-jdk17-0.0.1-jar-with-dependencies.jar
12 java -jar target/artifact-jdk17-0.0.1-jar-with-dependencies.jar
13 # Hello, world! 26-05-2023 17:05
14
pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
3 http://maven.apache.org/maven-v4_0_0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>com.example</groupId>
6 <artifactId>artifact-jdk17</artifactId>
7 <packaging>jar</packaging>
8 <version>0.0.1</version>
9 <name>artifact-jdk17</name>
10 <url>http://maven.apache.org</url>
11 <build>
12 <plugins>
13 <plugin>
14 <artifactId>maven-assembly-plugin</artifactId>
15 <version>3.6.0</version>
16 <configuration>
17 <descriptorRefs>
18 <descriptorRef>jar-with-dependencies</descriptorRef>
19 </descriptorRefs>
20 <archive>
21 <manifest>
22 <mainClass>hello.Main</mainClass>
23 </manifest>
24 </archive>
25 </configuration>
26 <executions>
27 <execution>
28 <id>make-assembly</id>
29 <phase>package</phase>
30 <goals>
31 <goal>single</goal>
32 </goals>
33 </execution>
34 </executions>
35 </plugin>
36 </plugins>
37 </build>
38 <dependencies>
39 <dependency>
40 <groupId>org.slf4j</groupId>
41 <artifactId>slf4j-api</artifactId>
42 <version>2.0.7</version>
43 </dependency>
44 <dependency>
45 <groupId>org.slf4j</groupId>
46 <artifactId>slf4j-simple</artifactId>
47 <version>2.0.7</version>
48 </dependency>
49 </dependencies>
50 <properties>
51 <maven.compiler.source>17</maven.compiler.source>
52 <maven.compiler.target>17</maven.compiler.target>
53 </properties>
54 </project>
src/main/java/hello/Main.java
1 package hello;
2
3 import java.util.Date;
4 import java.text.SimpleDateFormat;
5
6 class Main {
7 public static void main(String args[]) {
8 SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm");
9
10 for (;;) {
11 try {
12 Date d = new Date();
13 System.out.println("Hello, world! " + sdf.format(d));
14 Thread.sleep(60000);
15 } catch (Exception ex) {
16 ex.printStackTrace();
17 }
18 }
19 }
20 }
/etc/init.d/artifact-jdk17
1 #!/bin/sh
2 # chkconfig: 345 99 99
3 # description: Starts and stops the artifact-jdk17 process with user vagrant
4 # /etc/init.d/artifact-jdk17
5 USER=vagrant
6 PROG=artifact-jdk17
7 PIDFILE="/tmp/artifact-jdk17.pid"
8 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin"
9 LOG="/tmp/artifact-jdk17.log"
10 JAVA="/usr/bin/java"
11 JARFILE="/home/vagrant/fat-jar-jdk17/target/artifact-jdk17-0.0.1-jar-with-dependencies.jar"
12
13 start(){
14 echo "Start called $PROG with user $USER"
15 su - $USER -c "$JAVA -jar $JARFILE >> $LOG" &
16 /bin/sleep 2
17 PID=`ps uax| grep java | grep $PROG | grep $USER | awk '{print $2}'`
18 echo "Program $PROG running with PID: $PID"
19 echo "$PID" > $PIDFILE
20 }
21
22 status(){
23 PID=`cat $PIDFILE`
24 echo "Running $PROG with PID: $PID"
25 }
26
27 stop(){
28 echo "Stop called for $PROG"
29 PID=`cat $PIDFILE`
30 echo "PID to kill $PROG $PID"
31 kill -9 $PID
32 rm $PIDFILE
33 }
34
35 # switch
36 case "$1" in
37 start)
38 start
39 ;;
40 status)
41 status
42 ;;
43 stop)
44 stop
45 ;;
46 restart)
47 stop
48 start
49 ;;
50 *)
51 echo "$PROG start|status|stop|restart"
52 exit 1
53 ;;
54 esac
Steps to configure artifact-jdk17 service in Debian bullseye (11)
1 sudo bash
2 chmod 755 /etc/init.d/artifact-jdk17
3 # register service
4 update-rc.d artifact-jdk17 defaults
5 update-rc.d artifact-jdk17 defaults 20 80
6 update-rc.d artifact-jdk17 start 20 2 3 4 . start 30 5 . stop 80 0 1 6 .
7 # check if service will run on startup , + sign
8 service --status-all
9 # start service manually and check its status
10 service artifact-jdk17 start
11 service artifact-jdk17 status
12 # check if service is running with the PID mentioned in status
13 ps uax
14 tail -f /tmp/artifact-jdk17.log
15 # remove service from startup initialization
16 update-rc.d -f artifact-jdk17 remove
Attach debugger to mvn test
Listens on port 5005.
IntelliJ
- run
- attach debugger to process listening in 5005