【问题标题】:Maven Web Project with Apache Felix Plugin带有 Apache Felix 插件的 Maven Web 项目
【发布时间】:2013-10-16 20:20:06
【问题描述】:

使用 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>

Felix 插件

<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 模板是什么?

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

【问题讨论】:

  • 感谢布拉德的帮助

标签: maven osgi apache-felix osgi-bundle eclipse-virgo


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我的问题已经用下一个 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>
    

    【讨论】:

      猜你喜欢
      • 2012-09-27
      • 2015-08-15
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      相关资源
      最近更新 更多