Skip to content

Commit 0a2aa0a

Browse files
authored
Merge pull request #19 from tobespc/master
maven builds
2 parents 9e491ce + b3e85cc commit 0a2aa0a

File tree

15 files changed

+296
-9
lines changed

15 files changed

+296
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/web/.project

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The following data collection sources are built-in:
1919
The Application Metrics for Java agent requires Java version 8.
2020

2121
<a name="install"></a>
22+
2223
### Installation
2324

2425
Download the latest Application Metrics for Java release from [Github](http://github.com/runtimetools/javametrics/releases).
@@ -45,15 +46,18 @@ Coming soon
4546
Coming soon
4647

4748
<a name="api-doc"></a>
49+
4850
## API Documentation
4951
- [API Documentation](API-DOCUMENTATION.md)
5052

5153
<a name="building"></a>
54+
5255
## Building the jar and war files from source
5356

54-
Requirements: Apache Ant
57+
Requirements: Maven
5558

56-
Two `build.xml` ant build scripts are provided, one for building the javametrics.jar file and the other for building the javametrics.war fie.
59+
To build javametrics, run `mvn clean package` from the root project. This will build a zip file in the distribution directory containing
60+
`javametrics-agent.jar`, `javametrics-web.war` and a `lib/` directory with the `asm*.jar` files.
5761

5862
## Source code
5963
The source code for Application Metrics for Java is available in the [Javametrics Github project](http://github.com/RuntimeTools/javametrics).

distribution/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

distribution/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.ibm.runtimetools</groupId>
9+
<artifactId>javametrics</artifactId>
10+
<version>0.1.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>distribution</artifactId>
14+
<packaging>pom</packaging>
15+
<name>Distribution</name>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.ibm.runtimetools</groupId>
20+
<artifactId>javametrics-agent</artifactId>
21+
<version>0.1.0-SNAPSHOT</version>
22+
</dependency>
23+
</dependencies>
24+
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<artifactId>maven-assembly-plugin</artifactId>
30+
<executions>
31+
<execution>
32+
<id>distro-assembly</id>
33+
<phase>package</phase>
34+
<goals>
35+
<goal>single</goal>
36+
</goals>
37+
<configuration>
38+
<descriptors>
39+
<descriptor>src/assembly/bin.xml</descriptor>
40+
</descriptors>
41+
</configuration>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
</project>

distribution/src/assembly/bin.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
4+
<id>bin</id>
5+
<formats>
6+
<format>zip</format>
7+
</formats>
8+
9+
10+
<includeBaseDirectory>false</includeBaseDirectory>
11+
<moduleSets>
12+
<moduleSet>
13+
<!-- Enable access to all projects in the current multimodule build! -->
14+
<useAllReactorProjects>true</useAllReactorProjects>
15+
16+
<!-- Now, select which projects to include in this module-set. -->
17+
<includes>
18+
<include>com.ibm.runtimetools:javametrics-agent</include>
19+
<include>com.ibm.runtimetools:javametrics-web</include>
20+
</includes>
21+
<binaries>
22+
<outputFileNameMapping>${module.artifactId}.${module.extension}</outputFileNameMapping>
23+
<outputDirectory></outputDirectory>
24+
<unpack>false</unpack>
25+
<dependencySets>
26+
<dependencySet>
27+
<excludes>
28+
<exclude>org.ow2.asm:asm-tree*</exclude>
29+
<exclude>javax.servlet.jsp:jsp-api*</exclude>
30+
<exclude>javax.servlet:*</exclude>
31+
<exclude>javax.websocket:javax.websocket-api*</exclude>
32+
<exclude>javax.json:*</exclude>
33+
<exclude>com.ibm.runtimetools:javametrics-agent*</exclude>
34+
</excludes>
35+
<outputDirectory>/lib</outputDirectory>
36+
</dependencySet>
37+
</dependencySets>
38+
</binaries>
39+
</moduleSet>
40+
</moduleSets>
41+
</assembly>

java/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
/TEST-com.ibm.javametrics.dataproviders.MBeanDataProviderTest.xml
1111
/TEST-com.ibm.javametrics.dataproviders.MemoryPoolDataProviderTest.xml
1212
/TEST-com.ibm.javametrics.instrument.InstrumentTest.xml
13+
/target
14+
.settings

java/lib/asm/asm-5.0.4.jar

-52 KB
Binary file not shown.

java/lib/asm/asm-commons-5.0.4.jar

-40.8 KB
Binary file not shown.

java/pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
<parent>
3+
<groupId>com.ibm.runtimetools</groupId>
4+
<artifactId>javametrics</artifactId>
5+
<version>0.1.0-SNAPSHOT</version>
6+
</parent>
7+
<modelVersion>4.0.0</modelVersion>
8+
<artifactId>javametrics-agent</artifactId>
9+
<name>java</name>
10+
<description>Application Metrics for Java</description>
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>javax.servlet</groupId>
18+
<artifactId>javax.servlet-api</artifactId>
19+
<version>3.1.0</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>javax.servlet.jsp</groupId>
23+
<artifactId>jsp-api</artifactId>
24+
<version>2.2</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.ow2.asm</groupId>
28+
<artifactId>asm</artifactId>
29+
<version>5.0.4</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.ow2.asm</groupId>
33+
<artifactId>asm-commons</artifactId>
34+
<version>5.0.4</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>junit</groupId>
38+
<artifactId>junit</artifactId>
39+
<version>4.12</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.hamcrest</groupId>
44+
<artifactId>hamcrest-core</artifactId>
45+
<version>1.3</version>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
<build>
50+
<sourceDirectory>src</sourceDirectory>
51+
<testSourceDirectory>test</testSourceDirectory>
52+
<plugins>
53+
<plugin>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>3.6.1</version>
56+
<configuration>
57+
<source>1.8</source>
58+
<target>1.8</target>
59+
</configuration>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-jar-plugin</artifactId>
64+
<configuration>
65+
<archive>
66+
<manifestFile>src/meta-inf/MANIFEST.MF</manifestFile>
67+
</archive>
68+
</configuration>
69+
</plugin>
70+
<plugin>
71+
<artifactId>maven-dependency-plugin</artifactId>
72+
<executions>
73+
<execution>
74+
<phase>install</phase>
75+
<goals>
76+
<goal>copy-dependencies</goal>
77+
</goals>
78+
<configuration>
79+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
80+
</configuration>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
</project>

java/src/com/ibm/javametrics/instrument/Agent.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public class Agent {
3232

3333
private static final String CLASSTRANSFORMER_CLASS = "com.ibm.javametrics.instrument.ClassTransformer";
3434

35-
private static final String JAVAMETRICS_JAR_URL = "javametrics.jar!/";
35+
private static final String JAR_URL = ".jar!/";
36+
private static final String JAVAMETRICS = "javametrics";
3637

3738
private static final String ASM_VERSION = "5.0.4";
3839
private static final String ASM_JAR_URL = "asm/asm-" + ASM_VERSION + ".jar!/";
@@ -58,15 +59,21 @@ public static void premain(String agentArgs, Instrumentation inst) {
5859
* Determine the url to our jar lib folder
5960
*/
6061
String jarUrl = (Agent.class.getResource("Agent.class").toString());
61-
int jarIndex = jarUrl.indexOf(JAVAMETRICS_JAR_URL);
62+
63+
int jarIndex = jarUrl.indexOf(JAR_URL);
6264
if (jarIndex == -1) {
63-
System.err
64-
.println("Javametrics: Unable to start javaagent: Agent class not loaded from javametrics.jar");
65+
System.err.println("Javametrics: Unable to start javaagent: Agent class not loaded from jar: " + jarUrl);
6566
return;
6667
}
67-
String libUrl = jarUrl.substring(0, jarUrl.indexOf(JAVAMETRICS_JAR_URL));
6868

69-
URL[] urls = { new URL(libUrl + JAVAMETRICS_JAR_URL), new URL(libUrl + ASM_JAR_URL),
69+
/*
70+
* Determine root url and name of our jar
71+
*/
72+
String libUrl = jarUrl.substring(0, jarIndex);
73+
int jmIndex = libUrl.lastIndexOf(JAVAMETRICS);
74+
libUrl = jarUrl.substring(0, jmIndex);
75+
String jarName = jarUrl.substring(jmIndex, jarIndex + JAR_URL.length());
76+
URL[] urls = { new URL(libUrl + jarName ), new URL(libUrl + ASM_JAR_URL),
7077
new URL(libUrl + ASM_COMMONS_JAR_URL) };
7178
URLClassLoader ucl = new URLClassLoader(urls) {
7279

0 commit comments

Comments
 (0)