当前位置: 动力学知识库 > 问答 > 编程问答 >

How to configure OSGI in IntelliJ when it's handled by Maven

问题描述:

I'm an OSGI newb.

I can really use any guidance I can get regarding IntelliJ IDEA / OSGI / Maven / Sling.

So the actual Felix plugin dies when I load it. Apparently it hasn't been maintained and is no longer compatible with the latest release by which I mean IntelliJ IDEA 13.

So I've configured the framework to felix-framework-4.2.1, and that seems to work fine. My greatest concern is that if I apply the OSGI facet to a bundle, the settings seem to indicate that it will change the bundle. Since we have this set up in Maven, I don't think we want this. The source of the facet seems to be the Osmorc plugin. When I used it before, there were complaints about some packages in maven that weren't OSGI enabled and the IDE wanted to point to a special Spring repository for OSGI enabled jar dependencies.

Since we are doing this in Maven, should I even bother with Osmorc? Is there a better way to manage OSGI in IntelliJ IDEA? It is handy knowing which packages are OSGI enabled but an error for that? Really? Specifically I am referring to "The package is not exported by the bundle dependencies" showing up on imports and annotations.

网友答案:

My personal observation with Intellij IDEA 13 is that the OSGI project inspector is slightly more aggressive when it comes to profiling your classes that utilize non-osgi exported classes. That being said, a way around this is by adjusting the inspector severity level. This enables you to use the same OSGI-based approach you were using in Intellij IDEA 12.

To do this, go into your project settings (on Mac: Command+,) and then navigate to the following node:

Inspections --> OSGI --> Package accessibility

Once selected, you'll be able to change the severity level from error to warning.

Performing this change is requisite on a few changes in your pom.xml:

<dependencies>
.
.
    <dependency>
      <groupId>com.pkg.name</groupId>
      <artifactId>some-non-osgi-artifact</artifactId>
      <version>0.1-EXAMPLE</version>
   </dependency>
</dependencies>

<build>
    <plugins>
    .
    .
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>${maven-bundle-plugin.version}</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Version>${project.version}</Bundle-Version>
                    <Export-Package>
                        you.know.what.goes.here
                    </Export-Package>
                    <Private-Package>you.know.what.goes.here</Private-Package>
                    <Import-Package>
                        *
                    </Import-Package>
                    <Embed-Dependency>some-non-osgi-artifact;scope=compile|runtime;inline=false</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>
                    <Embed-StripGroup>true</Embed-StripGroup>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

Hope this helps, Ajay

网友答案:

I think your best bet currently is to use the maven bundle plugin to manage your imports and exports. This means intellij will simply see your bundles as maven projects. Still the correct jars should result. I handle OSGi bundles the same way in eclipse and it works fine.

I also read on the OSGi dev mailing list that there is a bndtools for intellij planned but this will for sure take a while.

分享给朋友:
您可能感兴趣的文章:
随机阅读: