Не се генерира OSGI-INF папка

Нов съм в OSGI. Имах проблеми с получаването на папка OSGI-INF в генерирания jar файл. Трябва да имам структура на папките, както е показано по-долу

  • МЕТА-ИНФ
  • OSGI-INF
  • Com.mine.cq

Използвам Eclipse и m2e плъгин. Когато стартирам проекта си, постигам УСПЕХ НА ИЗГРАЖДАНЕ. И получавам структурата на папките по-долу в този генериран jar файл.

  • МЕТА-ИНФ
  • Com.mine.cq

Ето моя POM.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mine.cq</groupId>
  <artifactId>mineCore</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mineCore</name>
  <url>http://maven.apache.org</url>

  <properties>
        <file.encoding>utf-8</file.encoding>
    </properties>
   <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.0-alpha-3</version>
                <executions>
                    <execution>
                        <id>enforce-java</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <message>Project must be built with Maven 2.0.7 or higher</message>
                                    <version>2.0.7</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <message>Project must be compiled with Java 5 or higher</message>
                                    <version>1.5.0</version>
                                </requireJavaVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>1.4.3</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>
                            com.mine.cq.mineCore.*
                        </Export-Package>
                        <Import-Package>
                            *;resolution:=optional,
                            javax.servlet;version=2.4,
                            javax.servlet.http;version=2.4
                        </Import-Package>
                        <Embed-Dependency>   
                        </Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                        <Include-Resource>{maven-resources}</Include-Resource>
                        <Sling-Bundle-Resources>/var/classes</Sling-Bundle-Resources>
                    </instructions>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.0</version>
                <configuration>
                    <goals>install</goals>
                </configuration>
            </plugin>
        </plugins>
    </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Защо папката OSGI-INF не е във файла .jar? Трябва да задам малко информация в папката OSGO-INF, тъй като трябва да регистрирам компонента си като OSGI услуга. Моля, насочете ме, за да го направя.


person Anderson    schedule 29.06.2013    source източник
comment
Докато експортирате JAR файла, избирате ли папката OSGI-INF. Не е избрано по подразбиране.   -  person Rohit Jain    schedule 29.06.2013
comment
Генерираният буркан няма папка OSGI-INF. Как мога да избера папка osgi-inf? Трябва ли да добавя добавки в pom.xml, за да генерирам OSGI-INF папка?   -  person Anderson    schedule 29.06.2013


Отговори (2)


Въпреки че закъснях доста, ще публикувам моите 2 цента по този въпрос за бъдещи справки.

Както вече беше посочено, можете да настроите „опаковката“ на пакета на „jar“, ако следвате инструкциите, дадени в Документация за приставка за Maven bundle.

Има само малка грешка: с тази конфигурация трябва изрично да добавите <exportScr>true</exportScr> в конфигурацията на приставката, за да създадете правилно SCR xml файла (също така не забравяйте да коригирате местоположението на манифеста, тъй като в документацията тази част отсъства!).

Можете да видите пример тук (той е напълно различен от вашия, но предполагам, че можете лесно да го намалите във вашия код, ако все още се интересувате):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.massimobono.karaf.examples</groupId>
    <artifactId>user-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <packaging>jar</packaging>    
    <build>
        <plugins>
            <plugin>
                <!-- Here you specifiy that you want to use the manifest file generated by maven bundle plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
            <!-- Here you generate the whole MANIFEST by using maven-bundle-plugin -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>3.2.0</version>
                <extensions>true</extensions> <!-- make sure this is present -->
                <executions>
                    <execution>
                        <id>bundle-manifest</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <manifestLocation>${project.build.outputDirectory}/META-INF/</manifestLocation> <!-- make sure this is present! in the example of maven bundle plugin documentation, this piece is NOT present -->
                    <exportScr>true</exportScr> <!-- be sure to add this line as well -->
                    <supportedProjectTypes>
                        <supportedProjectType>jar</supportedProjectType>
                        <supportedProjectType>bundle</supportedProjectType>
                        <supportedProjectType>war</supportedProjectType>
                    </supportedProjectTypes>
                    <instructions>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <_dsannotations>*</_dsannotations>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>6.0.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.osgi/org.osgi.service.component.annotations -->
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.component.annotations</artifactId>
            <version>1.3.0</version>
        </dependency>


    </dependencies>

</project>
person Koldar    schedule 22.11.2016

Вашият pom.xml трябва да има тип опаковка "bundle", а не "jar". Ако искате типът на опаковката да е "буркан", използвайте това:

http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html#ApacheFelixMavenBundlePlugin%28BND%29-AddingOSGimetadatatoexistingprojectswithoutchangingthepackagingtype

РЕДАКТИРАНЕ: О! Това е само първият проблем. Другият проблем е, че не мисля, че можете да генерирате OSGI-INF с maven-bundle-plugin. Трябва сами да създадете папката OSGI-INF в src/main/resources или да използвате плъгин, който генерира OSGI-INF.

Добавката maven-scr може да генерира OSGI-INF, но е полезна само ако използвате SCR. Maven SCR Plugin - Не генерира OSGI-INF папка

person Sheena Artrip    schedule 30.06.2013
comment
получавам грешка при компилиране на проект неизвестна грешка в пакета, когато променям в пакет вместо буркан. - person Anderson; 30.06.2013
comment
stackoverflow .com/questions/9732051/ Освен това можете да използвате другия метод, който ви позволява да използвате тип опаковка „буркан“. - person Sheena Artrip; 30.06.2013
comment
опаковъчният елемент трябва да бъде пакет, тъй като е пакет osgi. не получих никаква грешка в pom.xml. След командата за инсталиране на mvn получавам грешката Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test (default-test) on project cqcore: Execution default-test of goal org.apache.maven .plugins:maven-surefire-plugin:2.15:тестът е неуспешен: Задължителен клас липсваше при изпълнение на org.apache.maven.plugins:maven-surefire-plugin:2.15:test: org/apache/commons/lang3/StringUtils Бихте ли могли моля, кажете как да поправя този проблем? - person Anderson; 02.07.2013