2

使用maven创建一个简单的osgi(部署到virgo 服务器)项目的最佳方法是什么,以使用 pom.xml maven 描述符创建一个战争结构?

结构目标是

*.jsp
*.html
META-INF
MANIFEST (OSGI-CONFIG)
WEB-INF
  classes
  lib
  web.xml

然后当我创建一个项目

这是我的 pom.xml

项目属性

<groupId>com.aaaa</groupId>
<artifactId>first-maven-virgo-project</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>

菲利克斯插件

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <supportedProjectTypes>
            <supportedProjectType>war</supportedProjectType>
        </supportedProjectTypes>
        <instructions>
            <Export-Package>com.roshka.servlet</Export-Package>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>
            <Embed-Directory>WEB-INF/lib</Embed-Directory>
            <Embed-Dependency>*;scope=compile|runtime;</Embed-Dependency>
            <Embed-Transitive>true</Embed-Transitive>
            <Web-ContextPath>/hello</Web-ContextPath>
            <Webapp-Context>hello</Webapp-Context>
        </instructions>
    </configuration>
</plugin>

但是,当我执行mvn install打包时并没有创建MANIFEST文件,而是打包到 METAINF 文件夹中。

我的 felix 项目有什么问题?创建 OSGI BUNDLE 和 WAR OSGI BUNDLE 的典型 pom.xml 模板是什么?

ps 如果我将WAR TO BUNDLE更改为 Packaging Maven 描述符,生成的 JAR 工作正常,生成的 MANIFEST 正常。但它不是WEB结构。

4

2 回答 2

1

我的问题已经用下一个 pom.xml 解决了

<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.aaaa</groupId>
<artifactId>first-maven-virgo-project</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>

<description>http://localhost:8090/system/console/bundles</description>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-servlet-api</artifactId>
        <version>7.0.42</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>4.2.0</version>
        <scope>provided</scope>
    </dependency>

</dependencies>
<build>
    <plugins>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>./src/main/webapp/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <supportedProjectTypes>
                    <supportedProjectType>war</supportedProjectType>
                </supportedProjectTypes>
                <manifestLocation>./src/main/webapp/META-INF</manifestLocation>
                <instructions>
                    <Export-Package>com.roshka.servlet</Export-Package>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>
                    <Embed-Directory>WEB-INF/lib</Embed-Directory>
                    <Embed-Dependency>*;scope=compile|runtime;</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>
                    <Web-ContextPath>/hello</Web-ContextPath>
                    <Webapp-Context>hello</Webapp-Context>
                </instructions>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>

                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <Import-Package>javax.servlet,javax.servlet.http,javax.servlet.*,javax.servlet.jsp.*,javax.servlet.jsp.jstl.*,*</Import-Package>
                        <outputDirectory>./src/main/resources/WEB-INF/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <actTransitively>true</actTransitively>
                        <excludeScope>provided</excludeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <!-- Enable this plugin for all modules -->
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
        </plugin>
    </plugins>
</build>

于 2013-10-09T15:35:21.020 回答
1

IBM 的答案可以在此处找到,它逐步描述了该过程。可以开发一个脚本来创建一个给定战争的捆绑包,我已经用 java 编写了一个脚本,作为构建步骤调用。

一个关键的区别是 IBM 步骤将成品保留为 jar,而 jrey 将其保留为战争文件。这可能是因为 IBM 步骤可能会导致进一步的 CICS 捆绑,据我所知,这需要 jar,至少在使用 RAD 环境时是这样。

于 2017-07-20T11:39:55.503 回答