Wowza Community

Bundling External Libraries (jars) into a Wowza Plugin

When building Wowza plugins which require external dependencies (such as Apache Commons libraries), it is convenient to produce a single jar file for distribution, rather than relying on third parties to have the correct set of jars installed. The build.xml file in the Wowza IDE project can easily be converted to incorporate the contents of jar dependencies.

This example assumes that the jars to be included are in a folder called libs which in turn is located in the same folder as the src and bin directories (the root of the project).

After the core.build.dir property, add the following lines to build.xml:

	<property name="marshall.dir" value="tmp"/>
	<property name="addon.lib.dir" value="libs"/>

Then, replace the target section with

	<target name="jar">
		<mkdir dir="${marshall.dir}"/>
		<unzip dest="${marshall.dir}">
			<fileset dir="${addon.lib.dir}">
				<include name="**/*.jar"/>
			</fileset>
		</unzip>
		<jar jarfile="${wowza.lib.dir}/${jar.filename}">
			<fileset dir="${core.build.dir}"/>
			<fileset dir="${marshall.dir}"/>
		</jar>
		<delete dir="${marshall.dir}" />
	</target>

These changes define a the path to the jar files and a temporary directory to marshal them in. Then, Ant unzips all of the jar files to the temporary directory, and finally includes them when building the output jar.

A complete build.xml might look like:

<?xml version="1.0"?>
<project name="WowzaWatchdog" default="jar" basedir="..">
	
	<property name="wowza.lib.dir" value="/Library/WowzaMediaServer/lib"/>
	<property name="jar.filename" value="WowzaWatchdog.jar"/>
	<property name="core.build.dir" value="bin"/>
	<property name="marshall.dir" value="tmp"/>
	<property name="addon.lib.dir" value="libs"/>
	<target name="jar">
		<mkdir dir="${marshall.dir}"/>
		<unzip dest="${marshall.dir}">
			<fileset dir="${addon.lib.dir}">
				<include name="**/*.jar"/>
			</fileset>
		</unzip>
		<jar jarfile="${wowza.lib.dir}/${jar.filename}">
			<fileset dir="${core.build.dir}"/>
			<fileset dir="${marshall.dir}"/>
		</jar>
		<delete dir="${marshall.dir}" />
	</target>
	
</project>

All the best,

~ Christopher

How can I use the attached jar? What am I supposed to import so I had access to all classes of the jar file?

For example im include spymemcached.jar

import ???;

You will have to refer to their documentation:

http://docs.couchbase.org/spymemcached/2.6/

Richard

You might have to import the jar into the IDE project

Richard

You should put .jar files in the Wowza /lib folder

Richard

Did you restart Wowza after adding the .jar files to the /lib folder. That is necessary

Richard

See if you are not writing the [projectName].jar file to the /lib folder of an old Wowza install.

Richard

I tried

import net.spy.memcached

but the IDE highlights this line in red.

import spymemcached

with the same result.

Finally I did import the JAR file as an archive in the bin folder. Code in Wowza IDE is highlighted in red, but the project builds and runs fine.

Hi,

I had couple of external libraries that i needed, which i had copied into the wowza lib folder and had them referred into the project via ‘add external jars…’ in the project properties.

everything goes fine when i run the project in the IDE, but when i run it as standalone woza server i get java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64

I also, tried updating build.xml as mentioned and added the copies of the jar in ‘libs’ of project root, but it seems i cant get it to work on standalone wowza.

can someone please help me out here ?

yes, i did.

actually, i have external jars also in wowza lib and the project lib (so that means it ends up in the application jar as well)

it works absolutely fine in the IDE, but when i run the wowza server, i get that exception, probably because it’s not able to figure out the external jars.

I am not much of a java programmer. Am i missing something here ?

it seems it’s something to do with classpath, i have added that as environment variable pointing to the external jars. i need apache commons jar and mysql connector.

do i need to do something else as well ? i still cant make it work on standalone server

Old thread but thanks so much for this. I hope Wowza builds this in someday, I had 6 dependencies I was having to drag into my wowza/libs directory which is a ton of clutter and completely unrealistic to expect customers to do.