我正在开发简单的应用程序来演示Apache Karaf的使用。我在eclipse中开发了一个简单的基于maven的动态web项目。现在我想在apache karaf中部署它。以下是代码 -
Files.walkFileTree(Paths.get(Krawl.INDEXPATH), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
throws IOException {
// Do someting before directory visit
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
// Do something when a file is visited
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
throws IOException {
// Do Something after directory visit
return FileVisitResult.CONTINUE;
}
});
POM.Xml中的依赖
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class DemoActivator implements BundleActivator {
@Override
public void start(BundleContext bundleContext) throws Exception {
System.out.println("STARTING DEMO: hello, world");
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
System.out.println("STOPPING DEMO");
}
}
MANIFEST.MF
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_compendium</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
给定自定义MANIFEST文件的路径
Bundle-SymbolicName: osgi-example
Bundle-Version: 1.0.0.SNAPSHOT
Import-Package:com.psl.demo;version="1.0.0.SNAPSHOT",org.osgi.framework
Export-Package: com.psl.demo;version="1.0.0.SNAPSHOT"
Bundle-Activator: com.psl.demo.DemoActivator
现在每当我尝试使用 -
在karaf中安装应用程序时<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
我得到错误 -
执行命令时出错:安装软件包时出错:无法安装 bundle mvn:com.psl.demo / osgi-example / 1.0.0.SNAPSHOT: org.osgi.framework.BundleException:无法缓存包: MVN:com.psl.demo / OSGi的例子/ 1.0.0.SNAPSHOT
任何解决方案? TIA
答案 0 :(得分:0)
此错误即将到来是因为捆绑软件安装命令中的Maven坐标不正确。以下是相同的语法:
karaf@root()> bundle:install mvn:<group-id>/<artifact-id>/<version>
请验证pom.xml
的内容,并在上面的命令中输入相应的值。
从简单性的角度来看,您可以检查本地Maven存储库以查找包的位置,并相应地将值放在bundle install command
上方。