2014-05-19 3 views

답변

0

내가 한 번 그렇게 할 대상 플랫폼을 사용하려고했습니다. 그러나 일식 PDE는 매우 지저분하고 이상합니다.

오늘 OSGi 프로젝트를 관리하기 위해 Maven Bundle Plugin을 사용합니다. 이클립스 플러그인/플랫폼으로 작업해야하고 다른 선택의 여지가 없다면 felix maven 번들 플러그인 (http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html)을 사용하여 maven을 사용해 보시기 바랍니다.

내가하는 방식은 묶음이있는 하나의 마스터 프로젝트를 만드는 것입니다. 다음은 처음부터 이러한 프로젝트를 만드는 방법은 다음과 같습니다

enter image description here

는 첫째, (이상) 이클립스 케플러에, 새로운 받는다는 프로젝트를 만듭니다> 메이븐 프로젝트를 진행 파일 -> 새로 만들기로. 나타나는 새 창에서 프로젝트를 저장할 폴더를 선택하십시오. 작업 영역 또는 다른 폴더가 될 수 있습니다.

enter image description here

는 "(achetype 선택 건너 뛰기) 간단한 프로젝트 만들기"옵션을 선택하고 다음을 누릅니다. 그룹 ID 이름과 이슈 ID 이름을 채 웁니다. 이들은 각각의 프로젝트가 한 쌍으로 표현되는 maven 리파지토리에서 프로젝트를 식별하는 데 사용되는 매개 변수입니다 (프로젝트의 이름을 지정하는 데 왜이 방법을 사용했는지 묻지 마십시오). 원하는 이름을 지정할 수 있습니다. 방금이 프로젝트가 부모 POM이라는 것을 강조하기 위해 ".master"를 내 이슈 ID에 추가했습니다. 부모 POM은 개발하려는 모든 번들에 공통적 인 모든 정보가 포함 된 POM.XML 파일입니다.

enter image description here

을 눌러 마침. 이제 POM.XML을 보면 쓸모없는 정보와 그룹 및 이슈 ID가있는 줄이 거의 없습니다.

<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>such.osgi.example</groupId> 
<artifactId>very.example.master</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
</project> 

우리는 받는다는 우리가 펠릭스 아파치 받는다는 번들 플러그인을 사용하여, 번들을 만들려고하고 있다는 것을 이해하도록해야합니다. 더 구체적으로 당신의 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>such.osgi.example</groupId> 
      <artifactId>very.example.master</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
      <name>${project.artifactId}</name> 

      <properties> 
       <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding> 
      </properties> 

      <packaging>pom</packaging> 

      <modules> 
      </modules> 

      <profiles> 
       <!-- http://www.lucamasini.net/Home/osgi-with-felix/creating-osgi-bundles-of-your-maven-dependencies --> 
       <!-- -Pcreate-osgi-bundles-from-dependencies bundle:wrap --> 
       <profile> 
        <id>create-osgi-bundles-from-dependencies</id> 
        <build> 
         <directory>${basedir}/bundles</directory> 
         <plugins> 
          <plugin> 
           <groupId>org.apache.felix</groupId> 
           <artifactId>maven-bundle-plugin</artifactId> 
           <version>2.0.1</version> 
           <extensions>true</extensions> 
           <executions> 
            <execution> 
             <id>wrap-my-dependency</id> 
             <goals> 
              <goal>wrap</goal> 
             </goals> 
             <configuration> 
              <wrapImportPackage>;</wrapImportPackage> 
             </configuration> 
            </execution> 
           </executions> 
          </plugin> 
         </plugins> 
        </build> 
       </profile> 
      </profiles> 

      <build> 
       <sourceDirectory>src</sourceDirectory> 
       <testSourceDirectory>test</testSourceDirectory> 

       <plugins> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-compiler-plugin</artifactId> 
         <version>3.1</version> 
         <configuration> 
          <source>1.6</source> 
          <target>1.6</target> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.felix</groupId> 
         <artifactId>maven-bundle-plugin</artifactId> 
         <version>2.3.7</version> 
         <extensions>true</extensions> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-javadoc-plugin</artifactId> 
         <version>2.5</version> 
        </plugin> 
       </plugins> 
      </build> 

      <dependencies> 
       <dependency> 
        <groupId>junit</groupId> 
        <artifactId>junit</artifactId> 
        <version>4.8.1</version> 
       </dependency> 
       <dependency> 
        <groupId>org.apache.felix</groupId> 
        <artifactId>org.osgi.core</artifactId> 
        <version>1.4.0</version> 
       </dependency> 
       <dependency> 
        <groupId>org.apache.felix</groupId> 
        <artifactId>org.osgi.compendium</artifactId> 
        <version>1.4.0</version> 
       </dependency> 
      </dependencies> 
     </project> 

를 사용하면 의존성를 보면 당신은 우리의 모든 번들 (I를 JUnit을, org.osgi.core 및 org.osgi.compendium가 필요합니다 것을 볼 수 있습니다 갈라 eclipse 환경 밖에서 사용되지 않는 한, 춘분 (equinox)은 Eclipse PDE와 같은 엉덩이만큼 고통이기 때문에 펠릭스 구현을 선택하십시오. 기본적으로 maven은 maven의 중앙 저장소에서 이러한 종속성을 검색합니다.이 저장소는 우리가 처분 할 수있는 수많은 Java 라이브러리가있는 거대한 저장소입니다. 지금 프로젝트 탐색기 창에서 프로젝트를 선택하고 마우스 오른쪽 버튼으로 클릭하고 용접선을 실행로 이동합니다> 메이븐은 콘솔이 출력 볼 수 있습니다 설치 :

   SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
       SLF4J: Defaulting to no-operation (NOP) logger implementation 
       SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 
       [INFO] Scanning for projects... 
       [INFO]                   
       [INFO] ------------------------------------------------------------------------ 
       [INFO] Building very.example.master 0.0.1-SNAPSHOT 
       [INFO] ------------------------------------------------------------------------ 
       [INFO] 
       [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ very.example.master --- 
       [debug] execute contextualize 
       [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is p 
       latform dependent! 
       [INFO] Copying 0 resource 
       [INFO] 
       [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ very.example.master --- 
       [INFO] Nothing to compile - all classes are up to date 
       [INFO] 
       [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ very.example.mast 
       er --- 
       [debug] execute contextualize 
       [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is p 
       latform dependent! 
       [INFO] Copying 0 resource 
       [INFO] 
       [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ very.example.master 
       --- 
       [INFO] Nothing to compile - all classes are up to date 
       [INFO] 
       [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ very.example.master --- 
       [INFO] Surefire report directory: C:\Users\Pedro\workspace\very.example.master\target\surefire- 
       reports 
       Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.10 
       /surefire-junit3-2.10.pom 
       Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.10/ 
       surefire-junit3-2.10.pom (2 KB at 4.5 KB/sec) 
       Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.10 
       /surefire-junit3-2.10.jar 
       Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.10/ 
       surefire-junit3-2.10.jar (26 KB at 143.4 KB/sec) 

       ------------------------------------------------------- 
       T E S T S 
       ------------------------------------------------------- 

       Results : 

       Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

       [INFO] 
       [INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ very.example.master --- 
       [INFO] Building jar: C:\Users\Pedro\workspace\very.example.master\target\very.example.master-0. 
       0.1-SNAPSHOT.jar 
       [INFO] 
       [INFO] --- maven-install-plugin:2.3.1:install (default-install) @ very.example.master --- 
       [INFO] Installing C:\Users\Pedro\workspace\very.example.master\target\very.example.master-0.0.1 
       -SNAPSHOT.jar to C:\Users\Pedro\.m2\repository\such\osgi\example\very.example.master\0.0.1-SNAP 
       SHOT\very.example.master-0.0.1-SNAPSHOT.jar 
       [INFO] Installing C:\Users\Pedro\workspace\very.example.master\pom.xml to C:\Users\Pedro\.m2\re 
       pository\such\osgi\example\very.example.master\0.0.1-SNAPSHOT\very.example.master-0.0.1-SNAPSHO 
       T.pom 
       [INFO] ------------------------------------------------------------------------ 
       [INFO] BUILD SUCCESS 
       [INFO] ------------------------------------------------------------------------ 
       [INFO] Total time: 2.711s 
       [INFO] Finished at: Mon May 19 14:47:00 BST 2014 
       [INFO] Final Memory: 5M/15M 
       [INFO] ------------------------------------------------------------------------ 

공지 빌드 성공 부분을, 그건 매우 중요합니다, 그것은 모든 것이 지금까지 괜찮다는 것을 의미합니다! 이제 Run As -> Maven Build ...를 입력하고 -Pcreate-osgi-bundles-from-dependencies 번들을 입력하면 나타나는 창에서 "Goals"필드를 감싸고 Run을 누르면 메이븐 그 3 가지 의존성 (junit 및 org.orgi. *)을 다운로드하고 그들로부터 번들을 생성하십시오 (이 동작을 번들로 묶기라고 함). 이 프로젝트의 번들/디렉토리에있는 그 번들을 넣어 것입니다 : 프로젝트에서 당신은 또한 내가 여기에있는 것 외에 받는다는 의존성 또는 다른 폴더를 볼 경우

enter image description here

걱정하지 마십시오. 때로는 이클립스가 거기에 넣기도하고 때로는 그렇지 않아 마술처럼 느껴지기도합니다. 이상한 문제가 생겼다면 프로젝트를 선택하고 Maven -> Maven 프로젝트 업데이트로 가서 스냅 샷/릴리즈 강제 업데이트를 선택하고 프로젝트가 위 목록에서 선택되었는지 확인한 다음 Ok를 누릅니다.

enter image description here

이제 그 시간이 우리의 번들을 만들 수 있습니다.

enter image description here

: 우리는 하나 개의 간단한 번들을 만듭니다 간단하게하기 위해, 그래서 그것을 할 수있는 가장 쉬운 방법, 예를 들어, 우리의 프로젝트 내에서 새 폴더를 만들고 우리의 번들의 이름을 제공하는 것입니다 태그에 대한 very.example.master의 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> 

     <parent> 
      <relativePath>../pom.xml</relativePath> 
      <groupId>such.osgi.example</groupId> 
      <artifactId>very.example.master</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
     </parent> 

     <artifactId>very.example.mybundles.helloworldbundle</artifactId> 
     <packaging>bundle</packaging> 

     <build> 
      <sourceDirectory>src</sourceDirectory> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.felix</groupId> 
        <artifactId>maven-bundle-plugin</artifactId> 
        <extensions>true</extensions> 
        <configuration> 
         <instructions> 
          <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName> 
          <Bundle-Version>${project.version}</Bundle-Version> 
          <Export-Package>very.example.mybundles.helloworldbundle</Export-Package> 
          <Bundle-Activator>very.example.mybundles.helloworldbundle.Activator</Bundle-Activator> 
         </instructions> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
       </plugin> 
      </plugins> 
     </build> 

     <name>${project.artifactid}</name> 

     <properties> 
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     </properties> 

     <dependencies> 
      <dependency> 
       <groupId>org.zeromq</groupId> 
       <artifactId>zeromq-scala-binding_2.10</artifactId> 
       <version>0.0.7</version> 
      </dependency> 
     </dependencies> 
    </project> 

이로 교체 :

이제 다음과 같은 내용으로 해당 폴더 내의 pom.xml 파일을 생성

<modules> 
     <module>very.example.mybundles.helloworldbundle</module> 
    </modules> 

Eclipse에서 파일 -> 가져 오기 -> 기존 Maven 프로젝트를 수행하고 마스터 프로젝트의 폴더를 선택하면 eclipse가 새 프로젝트를 자동으로 감지합니다.

enter image description here

것은 마침을 명중하고 새로운 가져온 프로젝트를 찾습니다. POM 파일에 오류가 있음을 알게 될 것이지만 오 탐지됩니다. 지금은 무시하십시오. maven이 말하고자하는 것은 여러분이 프로젝트에 소스 파일 (즉, 번들 활성화 자)이 없다는 것입니다. 따라서 "src"라는 새 프로젝트 안에 새 폴더를 만들고 Activator.java를 안에 넣으십시오. 다음과 같이 그 코드는 다음과 같습니다

package very.example.mybundles.helloworldbundle; 

    import org.osgi.framework.BundleActivator; 
    import org.osgi.framework.BundleContext; 

    public class Activator implements BundleActivator { 

     @Override 
     public void start(BundleContext arg0) throws Exception { 
      System.out.println("hello world!"); 
     } 

     @Override 
     public void stop(BundleContext arg0) throws Exception { 
      System.out.println("bye!"); 
     } 

    } 

당신의 지금 오류가 없어야한다 프로젝트, 그리고 그것을 받는다는 완벽하게 설치 실행해야합니다! maven을 설치할 때마다 타겟/폴더에 .jar 파일이 생성됩니다. 그 .jar 파일은 OSGi 프레임 워크에 배포 할 수있는 프로젝트 번들입니다. 그러나 이제는 관련된 모든 의존성을 번들로 생성하여 OSGi Framework 런타임으로 이동할 수도 있습니다. 예를 들어,이 번들 POM 파일에 의존성을 넣었습니다. 실제 코드와 아무런 관련이 없습니다. 필요하지 않지만,이 번들에 대한 종속성이 있다면 maven이 어떻게 작동하는지 보여주기 위해이 파일을 배치했습니다. (Java Runtime Environment에 이미 포함되어있는 java.lang). 마스터 프로젝트를 선택하고 Run As -> Maven Build ...로 이동하여 -Pcreate-osgi-bundles-from-dependencies 번들을 입력하십시오 : 나타나는 창에서 "Goals"필드를 감싸고 Run을 누르면됩니다. 메이븐이 부모/마스터 프로젝트와 그 번들들로부터 모든 의존성을 다운로드하게하고 (우리의 상황에서는 우리는 단지 하나의 번들을 가지고있다.) 그들로부터 번들을 만든다. 이제 번들을 각 프로젝트의 번들/폴더 (master 및 helloworldbundle)에 있어야합니다. 이제 felix OSGi Framework를 다운로드하고 모든 jar와 함께 번들의 대상/디렉토리에있는 jar 파일을 felix 프레임 워크 번들/폴더에 복사하십시오.

enter image description here

참고 : 실행할 때마다 당신은 몇 가지 번들을 업데이트하고 런타임을 손상 갱신하는 경우에, 당신은 완전히 프레임 워크를 재설정 캐시 폴더를 삭제할 수 있습니다 펠릭스. cmd를 열고 felix 루트 경로로 이동하여 다음을 입력하십시오. java -jar bin \ felix.jar 큰 오류 메시지가 나타납니다. 이것은 번들의 pom 파일에 추가 한 예제 종속성 때문입니다. 그래서 그냥 예제 였기 때문에 삭제할 수 있습니다. 그래서 당신은이를 삭제해야합니다

<dependencies> 
      <dependency> 
       <groupId>org.zeromq</groupId> 
       <artifactId>zeromq-scala-binding_2.10</artifactId> 
       <version>0.0.7</version> 
      </dependency> 
     </dependencies> 

마십시오으로 실행이 -> 메이븐 새로운 펠릭스 프레임 워크로 대상/폴더의 .jar 생성 다시 이클립스 설치를 복사합니다. 거기에서 org.zeromq.scala-binding_2.10_0.0.7.jar 파일을 삭제하고 felix 프레임 워크를 다시 실행하십시오. 안녕하세요 세계 메시지가 표시됩니다. 이 도움이

enter image description here

희망!

이 링크에서는이 예제를 위해 만든 프로젝트와이 프로젝트가 배포 된 felix 프레임 워크를 찾을 수 있습니다.이 미니 자습서의 끝 부분에서 볼 수 있듯이 실행할 준비가되었습니다.

https://www.dropbox.com/s/pazhtrjmu50zsv9/example-source.zip

관련 문제