可以使用maven scr felix插件生成OSGI-INF/serviceComponent.xml,方法是添加依赖项,例如
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.15.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>但是对于gradle,我无法产生..。我已经尝试添加
buildscript {
dependencies {
classpath group:'be.jlr-home.gradle' , name:'scrPlugin', version:'0.1.0'
}}
apply plugin: 'java'
`apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'osgi'
apply plugin: 'scr'它给出的错误是be.jlr- found. be.jlr没有找到。
我做错什么了?
基本上,我需要在gradle中添加依赖项来生成servicecomponent.xml
发布于 2014-07-29 22:48:22
您的maven pom代码片段从felix为scr配置maven插件。您需要一个gradle插件来处理scr注释。我不知道费利克斯有没有。bnd项目增加了gradle支持(2.4.0.M1包括一个用于bnd的gradle插件),bnd可以处理DS的注释(但可能不是Felix的注释)。
发布于 2014-07-31 05:47:08
我已经解决了这个问题
将下面的行添加到您的gradle文件中,它就能工作了。
ant.properties.src = 'src/main/java'ant.properties.classes = 'build/classes/main' task genscr(dependsOn: compileJava) << { println ant.properties.classes ant.taskdef(resource: 'scrtask.properties', classpath: configurations.compile.asPath) ant.scr(srcdir: ant.properties.src, destdir: ant.properties.classes, classpath: configurations.compile.asPath) }
jar.dependsOn(genscr)
jar {
manifest {
// version = '1.0'
name = 'xxxxxxxxx'
instruction 'Service-Component', 'OSGI-INF/<PKGNAME>.<CLASSNAME>.xml' }
dependencies {
......//All other dependencies........
compile 'org.apache.felix:org.apache.felix.scr.annotations:1.9.8'
compile 'org.apache.felix:org.apache.felix.scr.ds-annotations:1.2.4'
compile group: 'org.apache.felix', name: 'org.apache.felix.scr.ant', version: '1.110.'}
sourceSets.main.compileClasspath += configurations.compile
发布于 2014-10-16 19:07:11
@saviour23的解决方案对我没有用。
事实证明,我们需要更改构建脚本,而gradle 1.6不能工作;在我升级到gradle 2.1之后,它工作得很好。
java代码:
import org.apache.felix.scr.annotations.*;
@Component
public class Bndtest {
public static void main(String[] args) {
System.out.println("Hello World");
}
}build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'be.jlr-home.gradle:scrPlugin:0.1.3'
}
}
apply plugin: 'java'
apply plugin: 'osgi'
apply plugin: 'scr'
apply plugin: 'groovy'
apply plugin: 'maven'
sourceCompatibility = 1.6
targetCompatibility = 1.6
version = '0.0.1-SNAPSHOT'
group = 'be.jlrhome.gradle.scr'
description = 'Gradle scr example'
dependencies {
compile 'org.apache.felix:org.apache.felix.scr.annotations:1.9.8'
}gradle将用正确的清单和OSGI包装一个jar。
https://stackoverflow.com/questions/25021151
复制相似问题