Eclipse Plug-in dependencies – Required Bundle vrs. Import-Package

本文探讨了在Eclipse插件开发中使用Require-Bundle与Import-Package声明依赖的区别。推荐使用Import-Package来降低插件间的耦合度,并讨论了不同情况下的适用场景。

Source:点击打开链接

Eclipse allows to define dependencies between plug-ins based on bundle or on package level. In the MANIFEST.MF of the plugin.xml you can tell that your plug-in should either depend on another plug-in (and all its exported packages) or if your plug-in should only depend on the availability of certain packages no matter which plug-in is exporting this package.

The corresponding statements in MANIFEST.MF are Require-Bundle: or Import-Package:

Today I got the question what approach should be preferred.

I believe the preferred way should be to use Import-Package because the coupling between the plug-ins is not that tight. As only as one plug-in exports this package the other plug-in will be fine. With this you can replaced a plug-in without changing the other plug-ins.

Of course if you have the same package in different plug-ins then you have to use the plug-in dependency.

The other advantage of plug-in dependencies is that the dependency is very clearly explicit, with the import-package it is not immediately obvious which plug-in is contributing this package.

But in total I would argue that loose coupling is always better so in general import-package should be preferred.


另外还有一篇文章关于OSGi Bundle Dependency写得非常漂亮:OSGi Bundle Dependency


<think>好的,我现在需要帮助用户解决在创建ROS 2包时遇到的命令行参数错误问题。用户想使用`ros2 pkg create`命令创建一个名为`my_package`的包,依赖`demo_nodes_cpp`,并且是在ROS 2 Humble版本中。 首先,我得回想一下`ros2 pkg create`的正确用法。根据用户提供的引用内容,比如引用[1]和引用[2],这两个例子展示了创建Python和CMake包的不同命令结构。用户的问题可能出在命令行参数的顺序或格式上。 正确的命令结构应该是:`ros2 pkg create <package_name> --build-type <build_type> --dependencies <dependencies>`。用户需要指定构建类型,比如`ament_cmake`或`ament_python`,因为`demo_nodes_cpp`是C++节点,所以应该使用`ament_cmake`作为构建类型。这时候用户可能之前没有正确指定构建类型,或者依赖项的位置不对。 然后,确认Humble版本的ROS 2是否支持这些参数。根据ROS 2的文档,这些参数在Humble中应该是有效的。接下来,检查依赖项的写法是否正确,多个依赖项应该用空格分隔,并且用逗号隔开吗?不,根据引用[1],`--dependencies`后面应该跟着用空格分隔的依赖项列表,比如`--dependencies rclpy`,所以正确的写法应该是`--dependencies demo_nodes_cpp`。 用户可能在命令中漏掉了构建类型,或者依赖项的格式错误。例如,如果用户没有指定`--build-type`,命令会报错,或者自动选择默认类型,但C++包通常需要`ament_cmake`。因此,正确的命令应该是: `ros2 pkg create my_package --build-type ament_cmake --dependencies demo_nodes_cpp` 然后,用户创建完成后需要编译,使用`colcon build`,并且source环境,再测试是否成功。引用[3]中的方法可以用来验证包是否正确安装,但需要调整,比如检查导入的模块或者编译后的可执行文件是否存在。 另外,用户提到的引用[4]关于启动文件的技巧可能不直接相关,但可以提醒用户在创建包后如何组织启动文件,但这可能超出当前问题的范围。 总结用户的潜在错误点:可能未指定`--build-type`,或者依赖项写法错误,或者包名位置不对。需要一步步指导用户正确的命令结构,并验证步骤。</think>在ROS 2 Humble中创建名为`my_package`的包时,请按照以下格式执行命令: ```bash ros2 pkg create my_package \ --build-type ament_cmake \ --dependencies demo_nodes_cpp \ --license Apache-2.0 ``` ### 关键参数说明 1. **构建类型**:C++包需指定`--build-type ament_cmake`(Python包则用`ament_python`)[^1][^2] 2. **依赖关系**:`--dependencies`参数后直接跟包名(支持多个依赖项空格分隔) 3. **许可证**:建议保留`--license Apache-2.0`以符合ROS规范 ### 验证步骤 1. 编译包 ```bash colcon build --packages-select my_package ``` 2. Source环境 ```bash source install/setup.bash ``` 3. 验证依赖继承(检查`package.xml`应包含`<depend>demo_nodes_cpp</depend>`) ### 常见错误规避 - 参数顺序错误:包名必须紧跟`pkg create` - 缺少构建类型:C++/Python包必须指定对应构建类型 - 依赖项拼写错误:注意ROS包名称的蛇形命名法(snake_case)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值