使用Maven开发OSGi应用程序时有两种主要方法:POM-first和MANIFEST first.
我正在寻找一个表格形式的答案,显示每种方法的优缺点.
更具体地说,我也想知道它与以下内容的关系:
我正在使用maven-shade-plugin在我的构建的包阶段重新定位一些包.我也使用maven-bundle-plugin来生成清单.问题是bundle插件在shade插件之前运行(在进程类阶段),并且在生成的manifest的导出中不包含任何阴影包.
我怎样才能使这两个插件彼此玩得很好,这样我的重定位包就像bundle插件一样对待任何其他包?
-
根据要求,我的POM的Shade和bundle部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>cglib:cglib</artifact>
<includes>
<include>net/sf/cglib/core/**</include>
<include>net/sf/cglib/proxy/**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>net.sf.cglib</pattern>
<shadedPattern>org.modelmapper.internal.cglib</shadedPattern>
</relocation>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>org.modelmapper.internal.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package>
org.modelmapper,
org.modelmapper.builder,
org.modelmapper.config,
org.modelmapper.convention,
org.modelmapper.spi
</Export-Package>
<Private-Package>
org.modelmapper.internal.**
</Private-Package>
<Import-Package>
*
</Import-Package>
<Include-Resource>
{maven-resources},
{maven-dependencies}
</Include-Resource>
</instructions>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
采取从这里
我在我的OSGi项目中使用了Felix Framework,但是我遇到了一个关于第三方依赖的严重问题.
我正在使用eclipse和maven-bundle-plugin从源代码生成我的bundle,从POM.XML文件生成MANIFEST.MF.到现在为止还挺好.然而,当我在我的包中有一些第三方依赖时,我发现自己正在寻找一个无限的JAR列表,它们通常不是捆绑包,并将它们放在我的/ bundle Felix目录中,直到不再缺少依赖项为止.
我将此过程称为"下载Internet以使我的OSGi应用程序正常工作".
我究竟做错了什么?当然,我必须做一些非常错误的事情,因为我无法想象任何人有一个依赖于B的捆绑A,然后依赖于C和D,然后这两个将取决于其他几个等等......去寻找所有这些依赖关系手动使用谷歌或maven中央!那太疯狂了!
什么是自动化的正确方法?我希望有两种解决方案之一:
1)能够创建一个嵌入了所有依赖项的大型JAR文件,但只导出我想要的包,而且只导出corse,而不是导入任何包.
2)(我的首选解决方案)有办法将我的所有依赖项都放到单独的JAR文件中,我可以简单地粘贴到/ bundle目录中.
3)(甚至更优选)有一种方法可以使用第三方JAR而无需将8GB的依赖项下载到我的项目中.
我找到了这样做的工具,但仅用于直接(1度)依赖关系,为我提供了传递依赖关系以便手动解决.
这个问题至关重要.缺少这样的工具会妨碍OSGi的使用.我搜索,搜索和搜索,我遇到了所有101种解决方案,如PAX,bndtools和朋友,但似乎他们没有解决这个问题......
请帮我.请提供一个活生生的例子,如果可以的话,世界各地的人都会从这个问题的解决方案中受益.
谢谢!
编辑:我附加了一个示例项目,我正在尝试使用JScience,但生成的JAR包不断询问我新的Imports,即它不是自包含的.
链接到示例:https://www.dropbox.com/s/svo3nu3vawvv2xn/RequireJscienceExample.zip?dl=0
我通常尝试使用Eclipse将第三方JAR转换为捆绑包,但它们总是必须导入我没有的包,所以这是一个无休止的情况,如你所说.
我找不到任何关于maven-bundle-plugin标签Conditional_Package的文档.但是相关的搜索显示我之前尝试过的内联选项没有成功.
我创建了一个基本项目,其中我有一个使用JScience库的类,在其POM.XML中我有以下内容:
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId};singleton:=true
</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>shared.properties.api, shared.properties.base
</Export-Package>
<Embed-Dependency>!org.osgi.*;scope=compile|runtime;inline=true</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
我说maven要内联所有不是来自osgi框架本身的包.看看生成的JAR看起来相当不错,我现在只嵌入了包而不是整个JAR(但是我认为我不需要所有那些内联包,因为我只使用其中两个).此外,如果我打开MANIFEST.MF文件,我可以看到这个有问题的行:
Manifest-Version: 1.0
Bnd-LastModified: 1414164534170
Build-Jdk: 1.6.0_65
Built-By: Pedro
Bundle-ManifestVersion: 2
Bundle-Name: RequireJscienceExample
Bundle-SymbolicName: RequireJscienceExample;singleton:=true
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: !org.osgi.*;scope=compile|runtime;inline=true …Run Code Online (Sandbox Code Playgroud) pax-runner apache-felix apache-karaf maven-bundle-plugin bndtools
我有一个java项目,可以编译成OSGi包.我正在使用maven-bundle-plugin来创建捆绑包,使用maven-sling-plugin将捆绑包推送到我正在运行的OSGi服务器.目前,我的项目有两个依赖项(Guava和Gson)需要在安装捆绑包之前手动安装在Felix服务器中.这两个依赖包的手动安装只需要发生一次(首次设置OSGi服务器时),但由于这是一个手动过程,我有点想将其推入"mvn install"阶段.
我看了很多maven插件(maven-sling-plugin,maven-ipojo-plugin,依赖插件等),但我担心我没有足够的知识知道从哪里开始,甚至在Stackoverflow中搜索解决方案(我怀疑这已经得到了解答).
那么 - 是否有一种干净的方式来安装/启动依赖捆绑与maven?我可以在哪里指定jar和运行级别,并在安装我的软件包之前进行安装?
http://svn.apache.org/repos/asf/felix/releases/maven-bundle-plugin-2.3.7/doc/site/wrap-mojo.html表示bundle:wrap已被弃用,与之相同bundle:bundleall.我目前用于wrap从非OSGi依赖项创建OSGi包,如http://www.lucamasini.net/Home/osgi-with-felix/creating-osgi-bundles-of-your-maven-dependencies所述.它们应该被替换为什么以及弃用的原因是什么?
我想构建一个符合OSGi标准的多模块应用程序,我在编译后将所有必需的包捆绑在3个文件夹中.我正在使用maven-bundle-plugin和maven-scr-plugin来创建捆绑包.
我想要的是用一个命令在一个osgi容器(Equinox)中运行这个应用程序,希望使用一个脚本.为此我相信我必须创建一个config.ini文件,列出应用程序中的所有bundle.
有没有办法在Maven编译时自己生成这个?或者有更好的方法来获取某些文件夹结构中的所有包,以便应用程序可以立即运行?
更新maven-bundle-plugin从版本2.3.5到版本2.4.0运行mvn clean install输出一些警告消息,我不完全理解.例如
Export ch.entwine.weblounge.contentrepository.impl.index, has 1, private references [org.elasticsearch.action.bulk]
我想这与嵌入式lib(elasticsearch)有关.以下是POM的部分内容:
<dependencies>
...
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.19.9</version>
</dependency>
...
</dependencies
...
<Export-Package>
...
ch.entwine.weblounge.contentrepository.impl.index
...
</Export-Package>
<Embed-Dependency>
....
elasticsearch;inline=true
...
</Embed-Dependency>
Run Code Online (Sandbox Code Playgroud)
错误消息到底意味着什么?解决此类问题的推荐方法是什么?
我正在使用maven-bundle-plugin(bnd有效)。
从源中包含资源文件很简单。
例如,在构建期间将资源文件 ( src/main/resources/some.xml) 移动到target目录 ( target/classes/some.xml)下,可以使用以下<Include-Resource>指令将其包含到包中:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Include-Resource>
some.xml=target/classes/some.xml,
</Include-Resource>
</instructions>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
让我们有一个依赖:
<dependency>
<groupId>com.example</groupId>
<artifactId>library</artifactId>
<version>1.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如何在依赖中引用资源文件jar?
换句话说,如何
指定如下内容:
com.example:library:1.0.0:jar/some.xml
Run Code Online (Sandbox Code Playgroud)而不是这个:
target/classes/some.xml
Run Code Online (Sandbox Code Playgroud)所以来自依赖项之一的资源出现在输出包中jar?
我正在构建一个OSGI基础应用程序,在我的一个类中我执行了大量的导入(大约30个),当我启动应用程序时,我得到了这个异常:
java.lang.ArrayIndexOutOfBoundsException: 18
at aQute.lib.osgi.Clazz.parseClassFile(Clazz.java:130)
at aQute.lib.osgi.Clazz.<init>(Clazz.java:65)
at aQute.lib.osgi.Processor.analyzeJar(Processor.java:159)
at aQute.lib.osgi.Processor.analyzeBundleClasspath(Processor.java:77)
at aQute.lib.osgi.Analyzer.analyze(Analyzer.java:194)
at aQute.lib.osgi.Builder.analyze(Builder.java:95)
at aQute.lib.osgi.Analyzer.calcManifest(Analyzer.java:293)
at aQute.lib.osgi.Builder.build(Builder.java:45)
at org.apache.felix.bundleplugin.BundlePlugin.buildOSGiBundle(BundlePlug...
Run Code Online (Sandbox Code Playgroud)
当我评论代码并减少进口数量一切顺利.
这似乎是一个OSGI限制,我该如何解决这个问题呢?
谢谢,
添加包含JPMS模块的依赖项后,maven-bundle-plugin(版本3.3.0)将失败:
[INFO] --- maven-bundle-plugin:3.3.0:bundle (default-bundle) @ my-bundle ---
[ERROR] Bundle myGroup:my-bundle:bundle:1.0 :
Exception: java.lang.ArrayIndexOutOfBoundsException: 19
[ERROR] Bundle myGroup:my-bundle:bundle:1.0 :
Invalid class file module-info.class (java.lang.ArrayIndexOutOfBoundsException: 19)
Run Code Online (Sandbox Code Playgroud)
似乎插件尝试(并且失败)来分析module-info.class,这在OSGi上下文中应该是无关紧要的.
osgi ×9
java ×5
maven ×5
bnd ×2
apache-felix ×1
apache-karaf ×1
bndtools ×1
import ×1
java-9 ×1
osgi-bundle ×1
pax-runner ×1
tycho ×1