The best way to convert an existing Java project into an OSGi package

We have many components, and we want to modularize only a few to start with Want to know what is the best way (in the context of my build environment) to create bundles in all these components?

My environment: Java 6, Maven 2.2 1,Hudson

Technology: Spring 3.0 5,WebSphere 7,Hibernate 3.2. X and most Apache Commons

requirement

>Combine only a few components Other components can export all packages. > When importing into eclipse, I should be able to see the bundle of the import package as a dependency in the build path (MVN Eclipse: Eclipse doesn't seem to do that)

Solution

First, just change manifest MF entries make all your artifacts bundles – they obviously don't work magically, but it's a good non-destructive first step

When using Maven bundle plugin, you can set the extension and supportedprojecttypes because you may encounter CI build problems. If the wrapper type is bundle, Maven repos and M2e will fail (see end)

Test your most risky / core external dependencies early – for example, if you use JPA for persistence, make sure the provider works in an OSGi environment with domain bindings and JDBC drivers

If you are migrating from Java EE / spring, check out karaf or Virgo However, if your components are used in embedded systems or have no external dependencies, Felix or equinox may be sufficient (if so, check the Pax URL project)

May it be worth editing your question to more specific domain / technology?

Eclipse: eclipse is only generated when the project is first configured. The life cycle problem of M2e may be a little painful, but it is far better than using the old Eclipse Plug-in

The following will add manifest entries to your existing artifacts without changing them in any other way It tells the standard Maven jar and war plug-ins to use the manifest generated by Maven bundle plugin MF.

Put it in the parent POM:

<pluginManagement>
<plugin>
    <groupId>org.apache.Felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.3.7</version>
    <extensions>true</extensions>
    <configuration>
        <archive>
            <addMavenDescriptor>true</addMavenDescriptor>
        </archive>
        <supportedProjectTypes>
            <supportedProjectType>jar</supportedProjectType>
            <supportedProjectType>war</supportedProjectType>
        </supportedProjectTypes>
        <instructions>
            <Built-By>${project.organization.name}</Built-By>
            <Bundle-Vendor>${project.organization.name}</Bundle-Vendor>
            <Bundle-ContactAddress>${project.organization.url}</Bundle-ContactAddress>
            <Bundle-Description>${project.description}</Bundle-Description>
            <Bundle-DocURL>${bundle.doc.url}</Bundle-DocURL>
            <Bundle-Category>${bundle.category}</Bundle-Category>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Bundle-Version>${project.version}</Bundle-Version>

            <Import-Package>*</Import-Package>
            <Export-Package>*</Export-Package>
        </instructions>
    </configuration>
    <executions>
        <execution>
            <id>bundle</id>
            <goals>
                <goal>manifest</goal>
            </goals>
            <phase>prepare-package</phase>
            <inherited>true</inherited>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <configuration>
        <archive>
            <manifestFile>${project.build.outputDirectory}/Meta-INF/MANIFEST.MF</manifestFile>
        </archive>
    </configuration>
</plugin>

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <executions>
        <execution>
            <id>create-war</id>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
            <inherited>true</inherited>
        </execution>
    </executions>
    <configuration>
        <archive>
            <manifestFile>${project.build.outputDirectory}/Meta-INF/MANIFEST.MF</manifestFile>
        </archive>
    </configuration>
</plugin>
</pluginManagement>

Then in the child POM, you can simply do:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.Felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
        </plugin>
        <!-- Below is mutually exclusive: Either jar or war plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
    </plugins>
</build>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>