欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

osgi+maven 创建项目有关问题总结

更新时间: 2014-05-17 20:45:51 责任编辑: Author_N7

 

osgi+maven 创建项目问题总结
最近公司的需在研究了一osgi 与maven 结合的开发。做了一个简单的技术预研。通多方面的分析决定采用Pax-Construct 创建项目。

Pax-Construct安装

    下载:http://repo1.maven.org/maven2/org/ops4j/pax/construct/scripts/1.4/scripts-1.4.zip

    设置环境变量:Path:C:\Pax-Construct-1.4\bin

    使用参考:http://www.ops4j.org/projects/pax/construct/
 
配置环境变量 pax/bin,maven/bin
执行以下命令:
1.pax-create-project -g gsoft -a g-osgi
  
   其中-g后代表groupId,-a代表artifactId
2.建立一个测试用的bundle:
cd g-osgi
pax-create-bundle -p com.gsoft.biz -n first.bundle
pax-create-bundle -p com.gsoft.biz.imp -n second.bundle
   其中,-p是包名package,-n是bundleName

3. 创建eclipse工程文件
mvn pax:eclipse -DdownloadSources
如下信息表示项目际创建成功:
[INFO] ------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] gsoft.g-osgi (OSGi project) ....................... SUCCESS [0.303s]
[INFO] g-osgi - plugin configuration ..................... SUCCESS [0.192s]
[INFO] g-osgi - wrapper instructions ..................... SUCCESS [0.004s]
[INFO] g-osgi - bundle instructions ...................... SUCCESS [0.004s]
[INFO] g-osgi - imported bundles ......................... SUCCESS [0.004s]
[INFO] gsoft.g-osgi.first.bundle [com.gsoft.biz] ......... SUCCESS [0.223s]
[INFO] gsoft.g-osgi.second.bundle [com.gsoft.biz.imp] .... SUCCESS [0.062s]
[INFO] ------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------
[INFO] Total time: 1.752s
[INFO] Finished at: Sun May 27 21:52:35 CST 2012
[INFO] Final Memory: 7M/111M

4.通过eclipse导入已存在工程将工程导入
执行 mvn clean install命令 出现如下异常
ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :first.bundle

使用 mvn clean install -X  -- 查看详细日志

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.ops4j:maven-pax-plugin:1.4:compile (default-compile) on project first.bundle: Execution default-compile of goal org.ops4j:maven-pax-plugin:1.4:compile failed: An API incompatibility was encountered while executing org.ops4j:maven-pax-plugin:1.4:compile: java.lang.NoSuchMethodError: org.apache.maven.project.MavenProject.addPlugin(Lorg/apache/maven/model/Plugin;)V
-----------------------------------------------------
realm =    plugin>org.ops4j:maven-pax-plugin:1.4
………………………………
修改 根项目的 pom.xml
加入 maven 资源库位置
关于这一块配置请参考
http://blog.csdn.net/arvinzhuo/archive/2009/06/05/4244061.aspx
<distributionManagement>
    <repository>
      <id>nexus-releases</id>
      <name>Nexus Releases</name>
      <url>http://localhost:8081/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
      <id>nexus-snapshots</id>
      <name>Nexus Snapshots</name>
      <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
  </distributionManagement>

项目根下的pom.xml 修改成以下的配置
<build>
    <plugins>
      <plugin>
        <groupId>org.ops4j</groupId>
        <artifactId>maven-pax-plugin</artifactId>
        <version>1.4</version>
        <configuration>
          <!--
           | some example Pax-Runner settings
          -->
          <provision>
            <param>--platform=felix</param>
          </provision>
        </configuration>
        <executions>
          <!--
           | uncomment to auto-generate IDE files
          <execution>
            <id>ide-support</id>
            <goals>
              <goal>eclipse</goal>
            </goals>
          </execution>
          -->
        </executions>
      </plugin>
    </plugins>
  </build>


改成如下内容
<build>
    <plugins>
      <plugin>
        <groupId>org.ops4j</groupId>
        <artifactId>maven-pax-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>1.4.3</version>
        <configuration>
          <provision>
            <param>--platform=equinox</param>
            <param>--vmOptions=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</param>
          </provision>
        </configuration>
        <extensions>true</extensions>
        <!-- 移动到这里 -->
      </plugin>
    </plugins>
  </build>



关于Pom.xml 配置请参考
http://springsfeng.iteye.com/blog/1389080

5.mvn clean install

………………………………………………
esults :

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

[INFO]
[INFO] --- maven-bundle-plugin:1.4.3:bundle (default-bundle) @ second.bundle ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ second.bundle ---
[INFO] Installing D:\osgi\osgi_lib_simple\g-osgi\second.bundle\target\second.bundle-1.0-SNAPSHOT.jar to d:\work\gsoft\g-osgi\second.bundle\1.0-SNAPSHOT\second.bundle-1.0-SNAPSHOT.jar
[INFO] Installing D:\osgi\osgi_lib_simple\g-osgi\second.bundle\pom.xml to d:\work\gsoft\g-osgi\second.bundle\1.0-SNAPSHOT\second.bundle-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-bundle-plugin:1.4.3:install (default-install) @ second.bundle ---
[INFO] Parsing file:/d:/work/repository.xml
[INFO] Installing gsoft/g-osgi/second.bundle/1.0-SNAPSHOT/second.bundle-1.0-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] gsoft.g-osgi (OSGi project) ....................... SUCCESS [0.199s]
[INFO] g-osgi - plugin configuration ..................... SUCCESS [0.064s]
[INFO] g-osgi - wrapper instructions ..................... SUCCESS [0.010s]
[INFO] g-osgi - bundle instructions ...................... SUCCESS [0.010s]
[INFO] g-osgi - imported bundles ......................... SUCCESS [0.010s]
[INFO] gsoft.g-osgi.first.bundle [com.gsoft.biz] ......... SUCCESS [2.074s]
[INFO] gsoft.g-osgi.second.bundle [com.gsoft.biz.imp] .... SUCCESS [0.721s]
[INFO] ------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------
[INFO] Total time: 4.423s
[INFO] Finished at: Sun May 27 22:00:17 CST 2012
[INFO] Final Memory: 15M/148M
[INFO] ------------------------------------
BUN 创建完成
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-05-17 20:45:51
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/827458/
本文WWW.DOC100.NET DOC100.NET版权所有。