Search code examples
jbossmaven-3jbossfusefuseesb

packaging maven project jboss fuse


In my project I connect to a mysql database. To deploy my jar on jboss fuse I need to add mysql-connector-java to the deploy folder. Do you have an idea how to package my project to deliver a single jar?


Solution

  • To embed a jar inside your bundle do the following:

    1) Declare it as a dependency

    <dependencies>
        <dependency>
            <groupId>com.your.company</groupId>
            <artifactId>your-needed-jar</artifactId>
            <version>1.3.4</version>
        </dependency>
    <dependencies>
    

    2) Tell maven-bundle-plugin to embed it.

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>3.0.1</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Embed-Dependency>your-needed-jar</Embed-Dependency>
                        <Import-Package>
                            eventually.unneded.pkg;resolution:="optional",
                            *
                        </Import-Package>
                        <Export-Package>
                            com.your.company.app.exportedpkg
                        </Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    While this work in general cases, there may be classloading issues with libraries which do a lot of runtime class proxying and class generation (like ORMs).

    IMHO a better approach would be to make the library available from JBoss Fuse itself. To do so:
    1) copy mysql-connector-java-xxx.java in JBoss Fuse lib/ directory
    2) edit config.properties in JBoss etc/ Fuse directory
    3) add com.mysql.jdbc package to the list

    org.osgi.framework.system.packages= \
     ...
     org.apache.karaf.diagnostic.core;version="2.4.0.redhat-621084", \
     com.mysql.jdbc;version="xxx", \
    

    Now you don't need to embed the library in your bundle, you can directly import it. The system bundle (ID:0) is exporting it.

    For further reference this PDF document may provide helpful information: Red Hat JBoss Fuse 6.2 Managing OSGi Dependencies