Как преодолеть проблему "Отсутствует необязательно импортированный пакет" в OSGi

Я написал пакет OSGi, используя "maven-bundle-plugin" (где я пытаюсь сделать "jruby-complete-1.4.0.jar" в качестве пакета osgi, обратите внимание, что единственной зависимостью является "jruby-complete-1.4.0.jar"). ").. Когда я проверяю комплект через консоль osgi с помощью команды diag ( #diag XX), он говорит, что некоторые пакеты отсутствуют;

osgi> diag 51
reference:file:dropins/jruby-complete-1.4.0.wso2v1.jar [51]
  Direct constraints which are unresolved:
    Missing optionally imported package com.sun.mirror.apt_0.0.0.
    Missing optionally imported package com.sun.mirror.declaration_0.0.0.
    Missing optionally imported package com.sun.mirror.type_0.0.0.
    Missing optionally imported package com.sun.mirror.util_0.0.0.
    Missing optionally imported package org.apache.bsf.util_0.0.0.
    Missing optionally imported package org.jgrapht_0.0.0.
    Missing optionally imported package org.jgrapht.graph_0.0.0.
    Missing optionally imported package sun.misc_0.0.0.

Мой пом, как;

<plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>

                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Name>${project.artifactId}</Bundle-Name>
                        <Export-Package>
                            com.kenai.*,
                            com.sun.jna.*,
                            org.jruby.*,
                            org.joni.*,                            
                        </Export-Package>
                        <Import-Package>                
                        *;resolution:=optional
                        </Import-Package>
                        <Fragment-Host>bsf-all</Fragment-Host>
            <DynamicImport-Package>*</DynamicImport-Package>    
            <Embed-Dependency>*;scope=compile|runtime;inline=true;</Embed-Dependency>       
                    </instructions>
                </configuration>
            </plugin>

Итак, я попытался добавить эти "необязательные пропущенные пакеты" в <Import-Package> опция как в pom[2] Но она дает больше проблем, таких как;

ference:file:dropins/jruby-complete-1.4.0.wso2v1.jar [51]
Constraints from the fragment conflict with the host: Import-Package: *; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.apt; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.declaration; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.type; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: com.sun.mirror.util; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.management; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.script; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: javax.swing.plaf.basic; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.apache.bsf; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.apache.bsf.util; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jgrapht; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jgrapht.graph; version="0.0.0"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.anno; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.exceptions; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.runtime; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: org.jruby.runtime.builtin; version="[1.4.0,2.0.0)"
Constraints from the fragment conflict with the host: Import-Package: sun.misc; version="0.0.0"
Direct constraints which are unresolved:
  Missing imported package com.sun.mirror.apt_0.0.0.
  Missing imported package com.sun.mirror.declaration_0.0.0.
  Missing imported package com.sun.mirror.type_0.0.0.
  Missing imported package com.sun.mirror.util_0.0.0.
  Missing imported package org.apache.bsf.util_0.0.0.
  Missing imported package org.jgrapht_0.0.0.
  Missing imported package org.jgrapht.graph_0.0.0.
  Missing optionally imported package org.jruby.anno_[1.4.0,2.0.0).
  Missing optionally imported package org.jruby.exceptions_[1.4.0,2.0.0).
  Missing optionally imported package org.jruby.runtime_[1.4.0,2.0.0).
  Missing optionally imported package org.jruby.runtime.builtin_[1.4.0,2.0.0).
  Missing imported package sun.misc_0.0.0.  

pom.xml [2];

 <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>

                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Name>${project.artifactId}</Bundle-Name>
                        <Export-Package>
                            com.kenai.*,
                            com.sun.jna.*,
                            org.jruby.*,
                            org.joni.*,                            
                        </Export-Package>
                        <Import-Package>                
                        com.sun.mirror.apt.*,
                        com.sun.mirror.declaration.*,
                        com.sun.mirror.type.*,
                        com.sun.mirror.util.*,
                        org.apache.bsf.util.*,
                        org.jgrapht.*,
                        org.jgrapht.graph.*,
                        sun.misc.*,
                          *;resolution:=optional
                        </Import-Package>
                        <Fragment-Host>bsf-all</Fragment-Host>
            <DynamicImport-Package>*</DynamicImport-Package>    
            <Embed-Dependency>*;scope=compile|runtime;inline=true;</Embed-Dependency>       
                    </instructions>
                </configuration>
            </plugin>

Как я могу преодолеть вышеуказанную проблему? Я экспортирую некоторые пакеты, которые мне нужны для других пакетов... Я что-то здесь не так делаю?

1 ответ

Эти пакеты являются необязательными для импорта, поэтому здесь не обязательно возникнет какая-либо проблема.

ОБНОВЛЕНИЕ после постера исправленный вопрос:

Эти зависимости были обнаружены плагином пакета при проверке байт-кода в вашем комплекте. Обычно они являются обязательными зависимостями, но по какой-то причине вы сделали их необязательными, добавив <Import-Package>*;resolution:=optional</Import-Package>, Не уверен, почему ты это сделал, но не бери в голову...

Правильный способ разрешения пакетов - это найти пакет, который их экспортирует. Например, вашему пакету нужен пакет org.jgrapht, Поэтому вам необходимо установить пакет, который экспортирует этот пакет.

Единственным исключением является sun.misc пакет, который, очевидно, исходит от JRE, но не должен использоваться вообще. Платформа OSGi не делает этот пакет доступным по умолчанию, но вы можете настроить их, добавив следующий параметр:

org.osgi.framework.system.packages.extra=sun.misc

Точный файл или место для размещения этого параметра зависит от вашей среды OSGi - вы не указали, какой из них вы используете, поэтому, пожалуйста, ознакомьтесь с его документацией о том, как передать параметры конфигурации.

Другие вопросы по тегам