You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Rune Engseth <ru...@engseth.net> on 2012/04/04 13:13:22 UTC

maven-bundle-plugin : Class in different directory than declared

Hi

I'm new to maven-bundle-plugin, hello to all, and here goes.

Environment:
Maven 3.0.4
OSX Lion
Java 6_29


Background:

An IBM consulentant was involved with a custom extension/plugin to a product running on Websphere.
The plugin is packaged as a OSGi bundle.
My part was to write and package all the business logic in a separate jar (as this also is used elsewhere, e.g. wars).
The plugin then uses classes from "my" jar file, which is assembled with all dependencies included and inlined. 

What I want to achieve:
Problem is, the IBM guy used Eclipse to package the bundle, and handed it over to me on a usb-stick, after deploying it to the OSGi container. No Maven, no SCM.
Being a java developer well familiarized with Maven, Git etc, I now want to add his code to github and use maven to build future refactorings to this plugin. 


What I did:
I unzipped the plugin he had already packaged. 
The structur was: 

./build.properties
./META-INF/MANIFEST.MF
./no/company/plugin/..  (this is where the plugin code goes.) 
./plugin.xml
./verticalsite-tfim-jar-with-dependencies.jar   ("my" custom jar)

The content of the Eclipse exported manifest file is:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Version: 1.0.0
Require-Bundle: com.tivoli.am.fim.common,com.tivoli.am.fim.sts
Bundle-SymbolicName: no.tine.fim.plugin.vs;singleton:=true
Bundle-Name: Map Plug-in
Bundle-Localization: plugin
Bundle-Vendor: TIVOLI
Bundle-ClassPath: .,verticalsite-tfim-jar-with-dependencies.jar



Now I want to recreate the structure and manifest using Maven.

After reading up on maven-bundle-plugin, and experimenting a lot, this is how my pom looks like. 


<project>

    <modelVersion>4.0.0</modelVersion>
    <groupId>no.company.tfim.plugin</groupId>
    <artifactId>groupsynch</artifactId>
    <packaging>jar</packaging>
    <version>1.0.0</version>

    <properties>
        <tfim.version>6.2.1</tfim.version>
        <verticalsite.version>3.2-jar-with-dependencies</verticalsite.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <instructions>
                        <Embed-Dependency>*;scope=compile;inline=false</Embed-Dependency>
                        <Include-Resource>{maven-resources}</Include-Resource>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId};singleton:=true</Bundle-SymbolicName>
                        <Bundle-Vendor>Company</Bundle-Vendor>
                        <Bundle-Name>Groupsynch Plug-in</Bundle-Name>
                        <Bundle-Localization>plugin</Bundle-Localization>
                        <Require-Bundle>com.tivoli.am.fim.common,com.tivoli.am.fim.sts</Require-Bundle>
                        <Export-Package>no.company.fim.plugin.vs.*</Export-Package>
                        <!--<_exportcontents></_exportcontents>-->
                        <Import-Package>!*</Import-Package>
                        <!--<Private-Package>*</Private-Package>-->
                        <Bundle-ClassPath>.,{maven-dependencies}</Bundle-ClassPath>
                    </instructions>
                    <supportedProjectTypes>
                        <supportedProjectType>jar</supportedProjectType>
                    </supportedProjectTypes>
                </configuration>
            </plugin>
        </plugins>

    </build>

    <dependencies>
        <dependency>
            <groupId>no.company</groupId>
            <artifactId>verticalsite</artifactId>
            <version>${verticalsite.version}</version>
            <scope>compile</scope>
        </dependency>
		rest of my deps goes here..
    </dependencies>

</project>


The structur of my project is:

./pom.xml
./src/main/java (plugin code goes here)
./src/main/resources/plugin.xml


Problem 1)

Reading the docs, I should use packaging "bundle". This does not work, and throws the following error

Unknown packaging: bundle @ line 12, column 16

I just switched to "jar", and it seems to work ok just the same, manifest.mf is created with bundle props etc. 


Problem 2)
When running the build with this pom, a get a lot of errors similiar to this:
[ERROR] Bundle no.company.tfim.plugin:groupsynch:jar:1.0.0 : Class in different directory than declared. Path from class name is no/company/verticalsite/VerticalSiteConfig.class but the path in the jar is target/classes/no/company/verticalsite/VerticalSiteConfig.class from 'Jar:verticalsite-3.2-jar-with-dependencies.jar'


So, I want to include the jar file, and set the Bundle-Classpath.
<Embed-Dependency>*;scope=compile;inline=false</Embed-Dependency> tells the bundle-plugin to include all deps with scope "compile", and inline is set to false. 

However I tweak the import/export packages, include-resource,embed-dependency instructions, I get the same errors

When removing the Embed-Dependency instruction, the build is successfull, but the jar is not included. 


So I'm a bit stuck at the moment

I have tried Google, and came across 
https://issues.apache.org/jira/browse/FELIX-660
which indicates that the bug is fixed, but I get the same errors, so I'm a bit confused.




Re: maven-bundle-plugin : Class in different directory than declared

Posted by Rune Engseth <ru...@engseth.net>.
Yes, the configuration is there to recreate the original manifest props. 

I now tried to remove all unnecessary configuration, relying on defaults.

However, even this simple config causes the error, so the main offender clearly is Embed-Dependency

<instructions>
                        <Embed-Dependency>verticalsite</Embed-Dependency>
</instructions>

Artifactid "verticalsite" refers to the first dependency in the deps list.


regards


Den 4. apr. 2012 kl. 13:40 skrev Robert Munteanu:

> 
> 
>> -----Original Message-----
>> From: Rune Engseth [mailto:rune@engseth.net]
>> Sent: Wednesday, April 04, 2012 2:32 PM
>> To: users@felix.apache.org
>> Subject: Re: maven-bundle-plugin : Class in different directory than
>> declared
>> 
>> Thanks, that resolved my first problem
>> 
>> However, the "Class in different directory than declared" still occurs
>> 
>> My refactored pom.xml now looks like
> 
> (snip)
> 
> You seem to have a lot of configuration items compared to what I usually do to have a bundle with an embedded jar.
> 
> This is what I recently used:
> 
> <configuration>
> 	<instructions>
> 		<Export-Package> com.example.package </Export-Package>
> 		<Private-Package> com.example.package.impl </Private-Package>
> 		<Import-Package> !com.sun.org.apache.xpath.*, * </Import-Package>
> 		<Embed-Dependency>com.example.embedded</Embed-Dependency>
> 	</instructions>
> </configuration>
> 
> Where com.example.embeded is the artifact id of the embedded jar. If you don't have that publicly available you can just declare a system dependency.
> 
> Robert
> 
>> 
>> <project>
>> 
>>    <modelVersion>4.0.0</modelVersion>
>>    <groupId>no.company.tfim.plugin</groupId>
>>    <artifactId>groupsynch</artifactId>
>>    <packaging>bundle</packaging>
>>    <version>1.0.0</version>
>> 
>>    <properties>
>>        <tfim.version>6.2.1</tfim.version>
>>        <verticalsite.version>3.2-jar-with-
>> dependencies</verticalsite.version>
>>    </properties>
>> 
>>    <build>
>>        <plugins>
>>            <plugin>
>>                <groupId>org.apache.felix</groupId>
>>                <artifactId>maven-bundle-plugin</artifactId>
>>                <version>2.3.7</version>
>>                <extensions>true</extensions>
>>                <configuration>
>>                    <archive>
>>                        <addMavenDescriptor>false</addMavenDescriptor>
>>                    </archive>
>>                    <instructions>
>>                        <Embed-
>> Dependency>*;scope=compile;inline=false</Embed-Dependency>
>>                        <Include-Resource>{maven-resources}</Include-
>> Resource>
>>                        <Bundle-
>> SymbolicName>${project.groupId}.${project.artifactId};singleton:=true</
>> Bundle-SymbolicName>
>>                        <Bundle-Vendor>company</Bundle-Vendor>
>>                        <Bundle-Name>Groupsynch Plug-in</Bundle-Name>
>>                        <Bundle-Localization>plugin</Bundle-
>> Localization>
>>                        <Require-
>> Bundle>com.tivoli.am.fim.common,com.tivoli.am.fim.sts</Require-Bundle>
>>                        <Export-
>> Package>no.company.fim.plugin.vs.*</Export-Package>
>>                        <!--<_exportcontents></_exportcontents>-->
>>                        <Import-Package>!*</Import-Package>
>>                        <!--<Private-Package>*</Private-Package>-->
>>                        <Bundle-ClassPath>.,{maven-
>> dependencies}</Bundle-ClassPath>
>>                    </instructions>
>>                </configuration>
>>            </plugin>
>>        </plugins>
>> 
>>    </build>
>> 
>>    <dependencies>
>> 
>>        <dependency>
>>            <groupId>no.company</groupId>
>>            <artifactId>verticalsite</artifactId>
>>            <version>${verticalsite.version}</version>
>>            <scope>compile</scope>
>>        </dependency>
>> 
>>        <dependency>
>>            <groupId>com.tivoli.am.fim</groupId>
>>            <artifactId>common</artifactId>
>>            <version>${tfim.version}</version>
>>            <scope>provided</scope>
>>        </dependency>
>> 
>>        <dependency>
>>            <groupId>com.tivoli.am.fim</groupId>
>>            <artifactId>sts</artifactId>
>>            <version>${tfim.version}</version>
>>            <scope>provided</scope>
>>        </dependency>
>> 
>> 
>>    </dependencies>
>> 
>> 
>> </project>
>> 
>> 
>> Den 4. apr. 2012 kl. 13:16 skrev Robert Munteanu:
>> 
>>>> -----Original Message-----
>>>> Problem 1)
>>>> 
>>>> Reading the docs, I should use packaging "bundle". This does not
>> work,
>>>> and throws the following error
>>>> 
>>>> Unknown packaging: bundle @ line 12, column 16
>>>> 
>>>> I just switched to "jar", and it seems to work ok just the same,
>>>> manifest.mf is created with bundle props etc.
>>> 
>>> You need to add
>>> 
>>> <extensions>true</extensions>
>>> 
>>> to your maven-bundle-plugin <plugin> ... </plugin> block.
>>> 
>>> For performance reasons customisations such as new packaging types
>> are contributed on-demand by Maven plugins.
>>> 
>>> Robert
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


RE: maven-bundle-plugin : Class in different directory than declared

Posted by Robert Munteanu <rm...@adobe.com>.

> -----Original Message-----
> From: Rune Engseth [mailto:rune@engseth.net]
> Sent: Wednesday, April 04, 2012 2:32 PM
> To: users@felix.apache.org
> Subject: Re: maven-bundle-plugin : Class in different directory than
> declared
> 
> Thanks, that resolved my first problem
> 
> However, the "Class in different directory than declared" still occurs
> 
> My refactored pom.xml now looks like

(snip)

You seem to have a lot of configuration items compared to what I usually do to have a bundle with an embedded jar.

This is what I recently used:

<configuration>
	<instructions>
		<Export-Package> com.example.package </Export-Package>
		<Private-Package> com.example.package.impl </Private-Package>
		<Import-Package> !com.sun.org.apache.xpath.*, * </Import-Package>
		<Embed-Dependency>com.example.embedded</Embed-Dependency>
	</instructions>
</configuration>

Where com.example.embeded is the artifact id of the embedded jar. If you don't have that publicly available you can just declare a system dependency.

Robert

> 
> <project>
> 
>     <modelVersion>4.0.0</modelVersion>
>     <groupId>no.company.tfim.plugin</groupId>
>     <artifactId>groupsynch</artifactId>
>     <packaging>bundle</packaging>
>     <version>1.0.0</version>
> 
>     <properties>
>         <tfim.version>6.2.1</tfim.version>
>         <verticalsite.version>3.2-jar-with-
> dependencies</verticalsite.version>
>     </properties>
> 
>     <build>
>         <plugins>
>             <plugin>
>                 <groupId>org.apache.felix</groupId>
>                 <artifactId>maven-bundle-plugin</artifactId>
>                 <version>2.3.7</version>
>                 <extensions>true</extensions>
>                 <configuration>
>                     <archive>
>                         <addMavenDescriptor>false</addMavenDescriptor>
>                     </archive>
>                     <instructions>
>                         <Embed-
> Dependency>*;scope=compile;inline=false</Embed-Dependency>
>                         <Include-Resource>{maven-resources}</Include-
> Resource>
>                         <Bundle-
> SymbolicName>${project.groupId}.${project.artifactId};singleton:=true</
> Bundle-SymbolicName>
>                         <Bundle-Vendor>company</Bundle-Vendor>
>                         <Bundle-Name>Groupsynch Plug-in</Bundle-Name>
>                         <Bundle-Localization>plugin</Bundle-
> Localization>
>                         <Require-
> Bundle>com.tivoli.am.fim.common,com.tivoli.am.fim.sts</Require-Bundle>
>                         <Export-
> Package>no.company.fim.plugin.vs.*</Export-Package>
>                         <!--<_exportcontents></_exportcontents>-->
>                         <Import-Package>!*</Import-Package>
>                         <!--<Private-Package>*</Private-Package>-->
>                         <Bundle-ClassPath>.,{maven-
> dependencies}</Bundle-ClassPath>
>                     </instructions>
>                 </configuration>
>             </plugin>
>         </plugins>
> 
>     </build>
> 
>     <dependencies>
> 
>         <dependency>
>             <groupId>no.company</groupId>
>             <artifactId>verticalsite</artifactId>
>             <version>${verticalsite.version}</version>
>             <scope>compile</scope>
>         </dependency>
> 
>         <dependency>
>             <groupId>com.tivoli.am.fim</groupId>
>             <artifactId>common</artifactId>
>             <version>${tfim.version}</version>
>             <scope>provided</scope>
>         </dependency>
> 
>         <dependency>
>             <groupId>com.tivoli.am.fim</groupId>
>             <artifactId>sts</artifactId>
>             <version>${tfim.version}</version>
>             <scope>provided</scope>
>         </dependency>
> 
> 
>     </dependencies>
> 
> 
> </project>
> 
> 
> Den 4. apr. 2012 kl. 13:16 skrev Robert Munteanu:
> 
> >> -----Original Message-----
> >> Problem 1)
> >>
> >> Reading the docs, I should use packaging "bundle". This does not
> work,
> >> and throws the following error
> >>
> >> Unknown packaging: bundle @ line 12, column 16
> >>
> >> I just switched to "jar", and it seems to work ok just the same,
> >> manifest.mf is created with bundle props etc.
> >
> > You need to add
> >
> > <extensions>true</extensions>
> >
> > to your maven-bundle-plugin <plugin> ... </plugin> block.
> >
> > For performance reasons customisations such as new packaging types
> are contributed on-demand by Maven plugins.
> >
> > Robert
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > For additional commands, e-mail: users-help@felix.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin : Class in different directory than declared

Posted by Rune Engseth <ru...@engseth.net>.
Thanks, that resolved my first problem

However, the "Class in different directory than declared" still occurs

My refactored pom.xml now looks like

<project>

    <modelVersion>4.0.0</modelVersion>
    <groupId>no.company.tfim.plugin</groupId>
    <artifactId>groupsynch</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0</version>

    <properties>
        <tfim.version>6.2.1</tfim.version>
        <verticalsite.version>3.2-jar-with-dependencies</verticalsite.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <instructions>
                        <Embed-Dependency>*;scope=compile;inline=false</Embed-Dependency>
                        <Include-Resource>{maven-resources}</Include-Resource>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId};singleton:=true</Bundle-SymbolicName>
                        <Bundle-Vendor>company</Bundle-Vendor>
                        <Bundle-Name>Groupsynch Plug-in</Bundle-Name>
                        <Bundle-Localization>plugin</Bundle-Localization>
                        <Require-Bundle>com.tivoli.am.fim.common,com.tivoli.am.fim.sts</Require-Bundle>
                        <Export-Package>no.company.fim.plugin.vs.*</Export-Package>
                        <!--<_exportcontents></_exportcontents>-->
                        <Import-Package>!*</Import-Package>
                        <!--<Private-Package>*</Private-Package>-->
                        <Bundle-ClassPath>.,{maven-dependencies}</Bundle-ClassPath>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>

    </build>

    <dependencies>

        <dependency>
            <groupId>no.company</groupId>
            <artifactId>verticalsite</artifactId>
            <version>${verticalsite.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.tivoli.am.fim</groupId>
            <artifactId>common</artifactId>
            <version>${tfim.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.tivoli.am.fim</groupId>
            <artifactId>sts</artifactId>
            <version>${tfim.version}</version>
            <scope>provided</scope>
        </dependency>


    </dependencies>


</project>


Den 4. apr. 2012 kl. 13:16 skrev Robert Munteanu:

>> -----Original Message-----
>> Problem 1)
>> 
>> Reading the docs, I should use packaging "bundle". This does not work,
>> and throws the following error
>> 
>> Unknown packaging: bundle @ line 12, column 16
>> 
>> I just switched to "jar", and it seems to work ok just the same,
>> manifest.mf is created with bundle props etc.
> 
> You need to add
> 
> <extensions>true</extensions>
> 
> to your maven-bundle-plugin <plugin> ... </plugin> block.
> 
> For performance reasons customisations such as new packaging types are contributed on-demand by Maven plugins.
> 
> Robert
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


RE: maven-bundle-plugin : Class in different directory than declared

Posted by Robert Munteanu <rm...@adobe.com>.
> -----Original Message-----
> Problem 1)
> 
> Reading the docs, I should use packaging "bundle". This does not work,
> and throws the following error
> 
> Unknown packaging: bundle @ line 12, column 16
> 
> I just switched to "jar", and it seems to work ok just the same,
> manifest.mf is created with bundle props etc.

You need to add

<extensions>true</extensions>

to your maven-bundle-plugin <plugin> ... </plugin> block.

For performance reasons customisations such as new packaging types are contributed on-demand by Maven plugins.

Robert


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org