Maven : OSGI, bundles and multi-modules projects - maven-2

I'm currently developing an OSGi based application (using Equinox) by trying to mavenize a web tutorial I've found on OSGi+Equinox. In this project, there are bundles depending on other bundles (quote-service depends on quote).
The compile phase does succeed, but the package phase does not. Maven complains the following :
[INFO] [bundle:bundle]
[ERROR] Error building bundle de.vogella.osgi:quote-service:bundle:0.0.1 : Unresolved references to [de.vogella.osgi.quote] by class(es) on the Bundle-Classpath[Jar:dot]: [de/vogella/osgi/quoteservice/Activator.class, de/vogella/osgi/quoteservice/QuoteService.class]
[ERROR] Error(s) found in bundle configuration
I do understand the problem, but do not see how to make it work.
This is the quote's pom :
<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>osgi-first-app</artifactId>
<groupId>de.vogella.osgi</groupId>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>de.vogella.osgi</groupId>
<artifactId>quote</artifactId>
<packaging>bundle</packaging>
<name>Quote Bundle</name>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<_include>src/main/resources/META-INF/MANIFEST.MF</_include>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
and the quote's bundle manifest :
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Quote Plug-in
Bundle-SymbolicName: de.vogella.osgi.quote
Bundle-Activator: de.vogella.osgi.quote.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.osgi.framework;version="1.3.0"
Export-Package: de.vogella.osgi.quote
Then the quote-service's pom :
<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>osgi-first-app</artifactId>
<groupId>de.vogella.osgi</groupId>
<version>0.0.1</version>
</parent>
<dependencies>
<dependency>
<groupId>de.vogella.osgi</groupId>
<artifactId>quote</artifactId>
<version>0.0.1</version>
<type>bundle</type>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>de.vogella.osgi</groupId>
<artifactId>quote-service</artifactId>
<packaging>bundle</packaging>
<name>Quote Service Bundle</name>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<_include>src/main/resources/META-INF/MANIFEST.MF</_include>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
And finally the quote-service's manifest :
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Quoteservice Plug-in
Bundle-SymbolicName: de.vogella.osgi.quoteservice
Bundle-Activator: de.vogella.osgi.quoteservice.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.osgi.framework;version="1.3.0", \
de.vogella.osgi.quote;version="0.0.1"
Is there something wrong ? Thank you in advance !

The answer is quite simple : I removed the already defined manifest, and used bnd entries in the bundle plugin instructions. That works !

Tycho is designed to handle these types of problems.

I wrote a tool called auto-builder: http://code.google.com/p/auto-builder. It introspects PDE-based projects and generates Ant build files; it supports transitive closure over dependencies and all that jazz.
I posted a write-up: http://empty-set.net/?p=9. I wrote it because the Maven tools I played with, when integrated with PDE, didn’t “just work.” Basically, I wanted to do coding in PDE and have a Hudson-based CI without any fuss in between.
Generating Ant files is nice because it gives you all the benefits of a declarative build tool, but it leaves you with a procedural description of what it is doing.
I am looking for more PDE-based projects to test it on. There are a couple RFC-0112 Bundle repositories around, and I have some code for downloading dependencies. If anyone is interested, then I could integrate dependencies download with auto-builder.

Related

Change version of product

I have a very basic project setup without sub-modules or anything. Just a pom.xml with nothing fancy:
<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>org.acme.product</groupId>
<artifactId>org.acme.product</artifactId>
<version>0.0.9</version>
<packaging>eclipse-repository</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>0.26.0</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>0.26.0</version>
<configuration>
<resolver>p2</resolver>
<target>
<artifact>
<groupId>org.acme.product</groupId>
<artifactId>org.acme.product</artifactId>
<version>${project.version}</version>
<classifier>platform</classifier>
</artifact>
</target>
<ignoreTychoRepositories>true</ignoreTychoRepositories>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Of course there is a target platform named platform.target with the feature org.eclipse.equinox.executable.feature.group. Finally there is a (empty) product with the same ID and version.
Now I want to use Tycho to update this version. It's only two files, I know. Still.
mvn org.eclipse.tycho:tycho-versions-plugin:set-version -DnewVersion=1.0.0
The pom.xml will get updated, but the product not. The same thing works with plug-ins and features, I can't figure out why it won't work with products, too.
Can somebody help to change the product's version?
Check if your pom.xml version and product version are the same.
The versions-plugin will only update the versions in product files if the old version matches the version in the eclipse-repository POM.
Product files whose versions are (intentionally) different from the POM version are not updated. This is the same as with modules: modules which don't have the same version as the root POM are not updated.
Refer to this bug report

maven tomcat7 redeploy lost file compared with the war file

I am using maven and tomcat7 to develop web project,but I found a weird problem:the redeployed project lost some files compared with the war file,thus I can not run the project after it redeployed.
Let me say it step by step:
This is the project structure of my maven project:
This is my configuration code of the pom.xml file:
<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.lucumt</groupId>
<artifactId>vm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>vm</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>4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<build>
<finalName>vm</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8085/manager/text</url>
<server>tm7</server>
<path>/vm</path>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
when I run tomcat7:deploy in eclipse using m2eclipse when tomcat7 is running,the project is packaged as vm.war and it will deployed in webapps folder for tomcat7,the file in vm folder will look like this,and I can run my project now:
But when I run tomcat7:redeploy,the file in the vm folder will look like below,the jsp and velocity file is missing and thus I can not run this project using tomcat again!
However,when I checked the vm.war file using WinRA,I found everything is okay,the jsp and velocity files are inside as below:
I think the files are missing when tomcat make the vm.war file in to vm,but I do not know why it happend,and I do not know how to solve it,can anyone help me? Is there is wrong configuration in my pom.xml file?
Thanks in advance!

FATAL ERROR while compiling Project using Maven 2

I am new to Maven and starting moving my project to maven. I have created the following POM.
when i issue install command, it gives me FATAL ERROR.
I am using maven 2.2.1 version and JDK 1.5.
My POM is as follows:
<?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>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<groupId>my.project.group</groupId>
<artifactId>my.artifact</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6.SEC01</version>
</dependency>
</dependencies>
</project>
Thanks for any help.
You are missing a mandatory tag from your project address structure groupId:artifactId:version
Put the following tag after ... with some version info (i.e. 1.x.x) and try.
<version>1.0.0</version>
Reference : http://maven.apache.org/pom.html

Converting a Maven 1 project into Maven 2

I'm new to Maven, and have been running into some difficulty in a project. I am to convert a Maven 1 project into Maven 2.
I started with these files:
maven.xml -- contains custom build scripts
project.properties -- general build settings
project.xml -- Project Object Model (POM) definition
From my understanding, Maven 2 project I must move these files into these:
pom.xml -- POM definition
(and possibly) settings.xml -- local configuration
I have gone about this by using the command 'mvn one:convert'.
This seemed to take care of project.xml > pom.xml
I then added a to pom.xml to include project.properties (which seemed to work).
Am I right in assuming that all I have left is to transfer over the contents of maven.xml >> pom.xml ?
maven.xml starts with:
<project default="site_deploy"
xmlns:ant="jelly:ant"
xmlns:maven="jelly:maven"
xmlns:j="jelly:core"
xmlns:util="jelly:util">
<ant:property environment="env"/>
and contains contains goals such as:
<goal name="site_deploy">
<attainGoal name="clean"/>
<attainGoal name="clean:clean"/>
<ant:delete dir="${maven.src.dir}/core/target" />
<attainGoal name="core_deploy"/>
</goal>
<goal name="core">
<maven:maven
descriptor="core/project.xml"
goals="jar:install"/>
<ant:property name="m2Dir" value="${maven.repo.local}/../../.m2/repository/app/${application.version}"/>
<ant:property name="m1Path" value="${maven.repo.local}/${application.id}/jars/${application.id}-core-${application.version}.jar"/>
<ant:echo message="copying jar m1 to m2 (${m1Path}) to (${m2Dir})" />
<ant:mkdir dir="${m2Dir}"/>
<ant:copy todir="${m2Dir}" file="${m1Path}" />
</goal>
From my reading if not bound to any build phase, goals can be executed outside of the build lifecycle by direct invocation, the second way being to write plugins for the goals.
How would I identify if the goals have dependencies-- how would I go about writing a plug-in? I've been referring mostly to the maven guides on apache.org, but some of it is hard to follow.
Here is the pom file generated:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>${application.id}</groupId>
<artifactId>${application.artifact}</artifactId>
<version>${application.version}</version>
<name>${application.name}</name>
<inceptionYear>2007</inceptionYear>
<organization>
<name>OrganizationName</name>
<url>http://organization.url</url>
</organization>
<scm>
<connection>scm:svn:connection</connection>
<url>http://svn.organization.local/svn/trunk/application_name</url>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-changes-plugin</artifactId>
<configuration>
<xmlPath>${basedir}/xdocs/changes.xml</xmlPath>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

Maven copy src/main/resources/services folder to /META-INF

EDIT
Ok I can be now more specific:
I have in my scr/main/resources a folder META-INF who contains services/javax.annotation.processing.Processor
My pom is still the same (with commented).
If I do "mvn clean install", the output jar will contains only the META-INF folder.
But if I rename the folder services, the output jar contains my classes and the META-INF folder with the new renamed folder and his content.
I have - I suppose - a easy question for regular maven2 users.
I have this simple pom for a simple subproject
<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>aida</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>aida-annotationProcessors</artifactId>
<packaging>jar</packaging>
<name>AIDA Annotation Processors</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<!-- <resources> -->
<!-- <resource> -->
<!-- <directory>src/main/resources/services</directory> -->
<!-- <targetPath>META-INF/services</targetPath> -->
<!-- </resource> -->
<!-- </resources> -->
</build>
<dependencies>
</dependencies>
</project>
My goal is simple:
I just want to copy my src/main/resources/services/javax.annotation.processing.Processor file in the {root}/META-INF/services folder of my generated jar.
But if I uncomment the resource part, my jar will contains only a META-INF folder without class!
Could you help me?
This is a bug/feature in the maven compiler plugin..
http://jira.codehaus.org/browse/MCOMPILER-97
A workaround is to disable annotation processing for the project containing the processor, -proc:none.
A more flexible solution would be to use an annotation processor for generating the services/javax.annotation.processing.Processor file, that way the classes are left intact and no extra work is required if the project depends on additional annotation processors.
META-INF/services generator is in main repo:
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
Annotate the processors with #MetaInfServices - note that I had to manually supply the annotation with Processor.class, otherwise it generated META-INF/services/javax.annotation.processing.AbstractProcessor
import org.kohsuke.MetaInfServices;
#MetaInfServices(javax.annotation.processing.Processor.class)
public class SoapPropertyProcessor extends AbstractProcessor
Here are the instructions from Apache for how to do that, but it appears that you're doing it correctly. Take a look at that page and make sure you're not making some small error.