在Liferay7.0中创建 common 工程


  1. maven 命令创建 2号 archetype  (maven command : mvn archetype:generate -Dfilter=liferay)

       关于使用 maven 创建 liferay 工程的详细步骤可查看: https://dev.liferay.com/zh/develop/tutorials/-/knowledge_base/7-0/generating-new-projects-using-archetypes

  2. 在需要引用 common 工程的 pom 文件中,引入 common 工程(添加 common 工程的 dependency)

  3. 修改 common 工程的 bnd.bnd文件,其中的 Export-Package :将指定的 package 导出到 jar 包。 用 ","分割,或者 .* 将所有 package 导出

      关于该步骤的具体信息,可查看 https://dev.liferay.com/zh_CN/develop/tutorials/-/knowledge_base/7-0/modularizing-an-existing-portlet


   可能遇到的问题:

           当我们在 common 工程中引入 Liferay 外部的 jar包时,我们往往是直接在 pom.xml 文件中添加需要引用的 jar 包的依赖。此时项目能正常编译,并且使用 maven 也能正常 build ,但是当部署项目时,会出现类似这样的报错信息: (这里的 com.xxxx.portal.common 就是我创建的 common 工程)

                 FrameworkEvent ERROR org.osgi.framework.BundleException: Could not resolve module: com.xxxx.portal.common [675]_  Unresolved requirement: Import-Package: org.apache.http_ [Sanitized] at org.eclipse.osgi.container.Module.start(Module.java:429)。

       解决该问题的方法: 打开 common 工程的 manifest.mf 文件(在打包 jar 文件时会生成在 target/classes/META-INF 目录下),在 Import-Package 中将提示错误导入的包删掉即可。 关于具体原因,可查看  http://www.howtobuildsoftware.com/index.php/how-do/DBC/eclipse-osgi-bundle-openhab-osgi-unresolved-requirement-import-package-compi4jiogpio


更新与:2017-7-4

      使用上述方法,手动删除 manifest.mf 的文件内容,显然是不合理的,因为每一次重新 build 工程, manifest.mf 文件又会重新生成。

      更好的解决办法是在 bnd.bnd 文件中过滤掉这些 package,那么每次生成 manifest.mf 文件的时候就不会导入这些包了,在 bnd.bnd 文件中加入如下语句:

      Import-Package:  !org.apache.http.*,*;



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值