Maven bundle plugin - How to add a main class

I have a maven maven project that has only one dependency: TestA. Here is the pom.xml for mjbean:

<groupId>com.mbean</groupId>
<artifactId>mjbean</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>

<build>
  <defaultGoal>install</defaultGoal>
  <plugins>
    <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <extensions>true</extensions>
      <configuration>
        <instructions>
          <Main-Class>com.mbean.Main</Main-Class>
          <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
          <Embed-Transitive>true</Embed-Transitive>
          <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
          <Import-Package>*</Import-Package>
        </instructions>
      </configuration>
    </plugin>
  </plugins>
</build>

<name>mjbean</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>com.testa</groupId>
    <artifactId>TestA</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </dependency>
</dependencies>

The main class is very simple:

package com.mbean;
import com.testa.Testcl;
public class Main {

public static void main(String[] args) {

    Testcl tcl = new Testcl();
    tcl.testmethod();
    }
}

I pointed out the main class <Main-Class>com.mbean.Main</Main-Class>in maven-bundle-plugin. This works well with Eclipse. Then I use Eclipse to create the target package in the target folder. When I try to run it on the command line: java -jar mjbean-0.0.1-SNAPSHOT.jarI got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/testa/Testcl
at com.mbean.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: com.testa.Testcl
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

Can anyone help me with this?

+5
source share
3 answers

Main-Class is not part of the OSGi package standard , and I do not believe that the maven-bundle-plugin will recognize it.

MANIFEST.MF

<_include>src/main/resources/META-INF/MANIFEST.MF</_include>

Main-Class . , , . jar, Maven, , maven-jar-plugin.

+1

, maven-bundle-plugin . , OSGI .

. , , ; , , BND .

.

<configuration>
    <instructions>
        <Main-Class>com.mbean.Main</Main-Class>
    </instructions>
</configuration>

, , ( jar ), , , , jar .

+3

maven-bundle-plugin pom...

   ...
    <configuration>
      <archive>
        <manifest>
           <mainClass>your.main.Main</mainClass>
        </manifest>
      </archive>
      ...

Roland

0

All Articles