Hi Ming,
Here is a sample pom.xml that uses the maven-assembly plugin to create a
single jar including the dependent jar files.
<dependencies>
<dependency>
<groupId>org.trafodion.jdbc.t4.T4Driver</groupId>
<artifactId>t4driver</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.trafodion.sql</groupId>
<artifactId>trafodion-sql</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.10</artifactId>
<version>0.9.0.0</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Venkat
-----Original Message-----
From: Liu, Ming (Ming) [mailto:[email protected]]
Sent: Sunday, May 01, 2016 6:46 AM
To: [email protected]
Cc: Hans Zeller <[email protected]>
Subject: 答复: TMUDF questions, jar dependencies
Thanks Kevin,
I tried the two ways, but both meet problems. I think there are some basic
misunderstanding. So I do need a step-by-step instructions about how to do
this.
First try:
Step 1: Use 'jar xvf' to extract all depended jars into a single folder:
solr (for example) Step 2: Then compile the UDR source java file: javac
solrUDR.java, this will generate a solrUDR.class. I copy this into the solr
folder created above Step 3: cd into 'solr'
Run 'jar cvf solrUDR.jar *'
It does generate a solrUDR.jar file, but at runtime, it still report 'class
not found'. I think jar file contains a MANIFEST.MF file, which now only
contains the last one when I do 'jar xvf' in the first step. So I still
cannot make it work. Not sure what should be the correct way to do this?
Then I switch to Maven approach, I use Eclipse this time, create a Maven
project, add dependencies and make a build, but still cannot get what I want
to get. There must be something very basic wrong, but for a java newbie,
that is a mountain to climb to understand what goes wrong... So a real
working example will really help me...
Here is the pom.xml I created:
<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>trafodion</groupId>
<artifactId>solrudf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>solrudf</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>5.5.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And 'mvn package' will generate a jar file. But as I run 'jar tf' against
it, it still not package all dependencies into the final jar file. I don't
know which part of pom.xml will tell the Maven to put all dependencies into
the final jar?
# jar tf solrudf-0.0.1-SNAPSHOT.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/maven/
META-INF/maven/trafodion/
META-INF/maven/trafodion/solrudf/
trafodion/
trafodion/solrudf/
META-INF/maven/trafodion/solrudf/pom.properties
META-INF/maven/trafodion/solrudf/pom.xml
trafodion/solrudf/solrUDF.class
META-INF/maven/trafodion/solrudf/pom.xml
META-INF/maven/trafodion/solrudf/pom.properties
Thanks,
Ming
-----邮件原件-----
发件人: Xu, Kai-Hua (Kevin) [mailto:[email protected]]
发送时间: 2016年5月1日 20:40
收件人: [email protected]
抄送: Hans Zeller <[email protected]>
主题: RE: TMUDF questions, jar dependencies
There is a simple way if you don't have too many JARs. A JAR is a zip file.
Unzip them and put them together, then pack them into one JAR. Another way
is to use Maven plugin( just put serveral lines into pom.xml), and run "mvn
package".
Best Regards,
Kevin Xu
-----Original Message-----
From: Liu, Ming (Ming) [mailto:[email protected]]
Sent: 2016年5月1日 19:00
To: [email protected]
Cc: Hans Zeller <[email protected]>
Subject: TMUDF questions, jar dependencies
Hi, all,
I was trying to write a sample TMUDF, which is using java. The UDF java code
invoke some functions provided by other jars. At runtime, I got
'classNotFound' issue. The function required by the sample needs many
depended jars, I still cannot find a way to correct put them in a single
jar. I am not good at java. If that is required, can anyone kindly give me
some real examples? I searched for many days 'how to put multiple jar into
one jar' but cannot find a real useful guide yet.
And what is a typical way to use TMUDF which has some jar dependencies?
I think in the Kafka UDF example, https://github.com/esgyn/code-examples
,one should add jars for Kafka as well, how did you do that?
Thanks,
Ming