带有 Apache Felix 插件的 Maven Web 项目

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

使用maven创建一个简单的osgi(部署到virgo服务器)项目的最佳方法是什么,用pom创建一个war结构.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 模板是什么?

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

最佳答案

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

关于带有 Apache Felix 插件的 Maven Web 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19272627/

相关文章:

java - 可以通过 OSGI 与运行在不同服务器上的组件进行通信

java - JAR 在 Lucee 上找不到 BouncyCaSTLeProvider

java - 获取已在 OSGi 中注册的服务时发生 ClassCastException

java - Swagger 专家提供

java - Maven 找不到父 POM

java - 使用 Gitlab CI 和 Junit 测试媒体播放器

java - 如何创建 OSGI 包?

java - Intellij Idea构建的jar的groupId和artifactId是什么?

hibernate - OSGi + hibernate

osgi - 使用 OSGi HTTP 服务启动 Wicket Web 应用程序