How can I add bundle to karaf Custom Distribution? - apache-karaf

I create karaf Custom Distribution
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.me</groupId>
<artifactId>root-karaf</artifactId>
<packaging>karaf-assembly</packaging>
<name>${project.artifactId}</name>
<version>4.0.4</version>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.0.4</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<version>4.0.4</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.0.4</version>
<extensions>true</extensions>
<configuration>
<!-- no startupFeatures -->
<startupFeatures>
</startupFeatures>
<installedFeatures>
</installedFeatures>
<bootFeatures>
<feature>standard</feature>
<feature>eventadmin</feature>
<feature>scr</feature>
</bootFeatures>
<excludedArtifactIds>
<artifactId>slf4j-api</artifactId>
</excludedArtifactIds>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now I want create example bundle and add to this Distribution or for example add this: <bundle>wrap:mvn:com.google.code.gson/gson/2.8.0</bundle> ti rhis Distribution. I thried this:
<bootFeatures>
<feature>standard</feature>
<feature>eventadmin</feature>
<feature>scr</feature>
<bundle>wrap:mvn:com.google.code.gson/gson/2.8.0</bundle>
</bootFeatures>
But it nit work
I create feature.xml and put to resources
<?xml version="1.0" encoding="UTF-8"?>
<features xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="platform-features"
xmlns="http://karaf.apache.org/xmlns/features/v1.0.0"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.0.0 http://karaf.apache.org/xmlns/features/v1.0.0">
<feature name="platform" version="${project.version}" install="auto">
<details>Service Platform</details>
<feature>test</feature>
</feature>
<feature name="test" version="4.0.4" install="auto">
<bundle>mvn:com.google.code.gson/gson/2.8.0</bundle>
</feature>
</features>

AFAIK you can not add bundle directly to <bootFeatures>. You should create your own feature that contains this bundle and add that feature to bootFeatures. Also, when you create your feature you don't need the wrap: part! gson 2.8 is already an OSGi bundle!

Related

Wrong Characters on javafx dialog

I used JOptionPane.showInputDialog and TextInputDialog for getting user input like this:
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("ورودی");
dialog.setHeaderText("لطفا شماره انبار را وارد کنید");
dialog.getDialogPane().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
Optional<String> anbarId = dialog.showAndWait();
anbarId.ifPresent(s ->
{
if (!s.equals("")) {
anbarLabel.setText(s);
}
}
);
but when i run executable jar file it shows me wrong characters:
Wrong characters on dialog
I used maven assembly plugin to create executable jar file here is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.ansar</groupId>
<artifactId>Jeticket</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.2.1.jre8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.ansar.application.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
finally i solved this problem by changing my jre version to 1.8.271 and using 'String.valueOf()'

JBoss EAP7 server throws ClassNotFoundException:org.apache.commons.beanutils eventhough EAR contains beanutils.jar

My Project structure is
parent
|---ejb-app.jar
|---restapi-app.war
|---ear-app.ear
I am using commons-beanutils to map the JavaEntity Bean to normal POJO class(DTO). The implementation of commons-beanutils is available inside ejb-app.jar.
Example: BeanUtils.copyProperties(destination, source);
My ear-app.ear aaplication packages the two modules such as ejb-app.jar & restapi-app.war. Below I have added pom.xml of ear-app.ear
<?xml version="1.0" encoding="UTF-8"?>
<parent>
<groupId>migration</groupId>
<artifactId>migration-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../migration-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.ear.app</groupId>
<artifactId>ear-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<name>ear-app</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.ejb.app</groupId>
<artifactId>ejb-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>org.restapi.app</groupId>
<artifactId>restapi-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2.redhat-1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<modules>
<ejbModule>
<groupId>org.ear.app</groupId>
<artifactId>ear-app</artifactId>
<bundleFileName>ejb-app-0.0.1-SNAPSHOT.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>org.restapi.app</groupId>
<artifactId>restapi-app</artifactId>
<contextRoot>/</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- WildFly plug-in to deploy EAR -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Problem:
When I deploy my aaplication in RedHat JBoss EAP7 server, I am getting the following error:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.beanutils.BeanUtils from [Module "deployment.ear-app-0.0.1-SNAPSHOT.ear.ejb-app-0.0.1-SNAPSHOT.jar:main" from Service Module Loader]

Project build error: Non-resolvable parent POM: Could not find artifact

Hi I have an sample project in Magnolia Blossom. When i run the project it is showing Error.
This is my pom.xml
<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>
<parent>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-parent-pom-community-module</artifactId>
<version>17</version>
</parent>
<groupId>com.hyro</groupId>
<artifactId>hyro-magnolia-blossom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Hyro Magnolia Blossom</name>
<description>Hyro Magnolia and Blossom working example</description>
<properties>
<magnolia.version>4.3.6</magnolia.version>
<blossom.version>1.1.1</blossom.version>
<spring.version>3.0.4.RELEASE</spring.version>
</properties>
<build>
<resources>
<!-- Add the Attributes from the POM to properties files -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<!-- Compiler version -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Add timestamp to configuration files -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<inherited>true</inherited>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,date,yyyy-MM-dd'T'HH:mm:ss.SSS'+10:00'}</format>
<items>
<item>timestamp</item>
</items>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Magnolia Dependencies -->
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-core</artifactId>
<version>${magnolia.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-mail</artifactId>
<version>${magnolia.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-gui</artifactId>
<version>${magnolia.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-admininterface</artifactId>
<version>${magnolia.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-templating</artifactId>
<version>${magnolia.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-fckeditor</artifactId>
<version>${magnolia.version}</version>
<scope>provided</scope>
</dependency>
<!-- Blossom Module -->
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-blossom</artifactId>
<version>${blossom.version}</version>
<scope>provided</scope>
</dependency>
<!-- Logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<!-- Spring MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
at the it is showing the following error:
Project build error: Non-resolvable parent POM: Could not find artifact info.magnolia:magnolia-parent-pom-community-module:pom:1.0.12-SNAPSHOT and 'parent.relativePath' points at wrong local POM
some where i got an idea of deleting all the *lastupdated.xml file but it is not helping.
Anything wrong with the Pom.xml ?
can anyone suggest me how to resolve this.
I tried building your pom. It was missing </project> at the end. I assume this was just copy paste error. Anyway it built fine for me using maven 3.2.1. I did verify info.magnolia:magnolia-parent-pom-community-module:pom:1.0.12-SNAPSHOT does not exist in the nexus.
I did a mvn dependency:tree on your pom and I don't see any dependency on the pom referenced in your error. Maybe you should try and analyze the pom and your end and see where this dependency is being brought in.
Looking at Magnolia Nexus the latest version of parent pom is 29. Your one is quite old. I suggest you change your pom to
<parent>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-parent-pom-community-module</artifactId>
<version>29</version>
</parent>
HTH,
Jan

Magnolia Activation Module (version 5.1.0) Ensures that the key property 'magnolia.author.key.location' is present in the Magnolia properties file

I have checked out the following example project ant tried to get it started with magnolia 5
http://svn.magnolia-cms.com/svn/community/magnolia/tags/magnolia-4.3.1/magnolia-empty-webapp
I have updated maven dependencies, fixed a ton of exeptions and errors and my magnolia-empty-webapp pom.xml looks now like this:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>magnolia-project</artifactId>
<groupId>info.magnolia</groupId>
<version>5.2.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>magnolia-empty-webapp</artifactId>
<packaging>war</packaging>
<name>magnolia-empty-webapp</name>
<description>The basic Magnolia webapp on which projects can depend.</description>
<profiles>
<profile>
<id>with-optional-modules</id>
<dependencies>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-workflow</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-dms</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-samples</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-templating</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-core</artifactId>
<!-- <version>5.2.4</version> -->
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-standard-templating-kit</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-legacy-admininterface</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-admincentral</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>info.magnolia.activation</groupId>
<artifactId>magnolia-module-activation</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-templating</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>info.magnolia.cache</groupId>
<artifactId>magnolia-module-cache</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-jaas</artifactId>
<!-- <version>4.3.1</version> -->
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-framework</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-contentapp</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-scheduler</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>info.magnolia.security</groupId>
<artifactId>magnolia-security-app</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-fckeditor</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-mail</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-categorization</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.openutils</groupId>
<artifactId>openutils-log4j</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-demo-project</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-dms</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<!-- these are the resources copied by the remote-resources-plugin -->
<directory>${basedir}/target/maven-shared-archive-resources</directory>
<excludes>
<exclude>**/*</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>src/main/webapp/cache</directory>
</fileset>
<fileset>
<directory>src/main/webapp/logs</directory>
</fileset>
<fileset>
<directory>src/main/webapp/repositories</directory>
</fileset>
<!-- <fileset> -->
<!-- <directory>src/main/webapp/templates</directory> -->
<!-- </fileset> -->
<fileset>
<directory>src/main/webapp/tmp</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<!-- these are the resources copied by the remote-resources-plugin -->
<directory>${basedir}/target/maven-shared-archive-resources</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
</configuration>
</plugin>
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>winstone-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>embed</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>magnolia.nexus.public</id>
<url>http://nexus.magnolia-cms.com/content/groups/public</url>
</repository>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>magnolia</id>
<url>http://repo.magnolia-cms.com/m2</url>
</pluginRepository>
</pluginRepositories>
</project>
Now when I start magnolia-empty-project, I come to the magnolia installation page. When I click on "Start installation", it comes the following message:
BTW if anyone runs into this issue, to get rid of it, go to WEB-INF/config/default/magnolia.properties and add something like:
magnolia.author.key.location=${magnolia.home}/WEB-INF/config/default/magnolia-activation-keypair.properties
Pls note that while this is fine for development, you should keep all the files, incl. the keys outside of the (exploded) war file for production use.
Also related (but off topic for the discussion) - you should not need to have DMS in your pom file. Magnolia 5 doesn't need DMS. It was replaced by DAM. Pom file above looks like generated by some old version of the archetype or copied from old project.
HTH,
Jan
Max,
I think the problem here is that you are mixing up two different versions of Magnolia. You say you checked out the empty webapp tagged 4.3.1 and then made a lot of changes to it. Have you tried checking out a v5 webapp from the Git repository that replaces the SVN one?
Alternatively, you may find it easier to use the Maven archetypes.
here is the easiest way to get magnolia5 running with an empty-project:
http://www.youtube.com/watch?v=aU7q3daQ8S0#t=133

ClassNotFoundException in Maven project

There is a maven based project, which can be built by maven install, but throw exception when run the out jar:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/CommandLineParser
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.CommandLineParser
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I want to know why java can not find the maven dependency library ?
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.artofsolving.jodconverter</groupId>
<artifactId>jodconverter-core</artifactId>
<version>3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>JODConverter - Core Library</name>
<description>
JODConverter converts office documents using OpenOffice.org
</description>
<url>http://jodconverter.googlecode.com</url>
<licenses>
<license>
<name>GNU Lesser General Public License, Version 3 or later</name>
<url>http://www.gnu.org/licenses/lgpl.html</url>
</license>
</licenses>
<scm>
<url>http://jodconverter.googlecode.com/svn/trunk/jodconverter-core</url>
<connection>scm:svn:https://jodconverter.googlecode.com/svn/trunk/jodconverter-core/</connection>
</scm>
<inceptionYear>2003</inceptionYear>
<developers>
<developer>
<id>mirko.nasato</id>
<name>Mirko Nasato</name>
<email>mirko#artofsolving.com</email>
</developer>
</developers>
<contributors>
<contributor>
<name>Shervin Asgari</name>
<email>shervin#asgari.no</email>
</contributor>
</contributors>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<!-- required for org.hyperic:sigar -->
<id>jboss-public-repository-group</id>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository>
</repositories>
<dependencies>
<!-- Required dependencies -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>juh</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>ridl</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>unoil</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<!-- for the command line tool -->
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
<!-- Optional dependencies -->
<dependency>
<!-- for more robust process management -->
<groupId>org.hyperic</groupId>
<artifactId>sigar</artifactId>
<version>1.6.5.132</version>
<optional>true</optional>
</dependency>
<dependency>
<!-- for JSON configuration -->
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<optional>true</optional>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<!-- don't run tests in parallel -->
<perCoreThreadCount>false</perCoreThreadCount>
<threadCount>1</threadCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<mainClass>org.artofsolving.jodconverter.cli.Convert</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dist.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</reporting>
</project>
When running your Jar with java -jar, you're no longer running with the maven resolving of dependencies. You have to make sure that all the jars you depend on are available at the relative loacation specificied in the MANIFEST.mf file in your Jar. Usually, you would use the assembly plugin to create a distributable archive that creates this structure. Or you could use a uberjar/onejar plugin to included everything inside your Jar.
You have 2 options to fix this:
Option 1 - use both plugins below to copy dependencies to a "lib" folder (see outputDirectory) and make your Runnable JAR know where they are (see classpathPrefix)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>example.MyMainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
Option 2 - Use maven-assembly-plugin to create a single JAR with all dependencies included. (all dependencies are extracted and compressed together in the same JAR)
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>compile</scope>
</dependencySet>
</dependencySets>
I've seen the problem, too. Cobertura creates instrumented copies of all compiled classfiles (in target/classes) by bytecode manipulation. My jar file contained the instrumented class files (from target/generated-classes/cobertura), but cobertura.jar was missing. So, ClassNotFoundException was the right reaction.
However, since my POM doesn't contain any hint, which are the intended classes for packaging, Maven has the free choice ... and it uses the instrumented set of files.
My solution was really simple: mvn clean and mvn package. The first call removes all instrumented classes. Then, the second call finds only the uninstrumented classes without any external references to Cobertura.

Resources