You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级OSGi项目时如何在Eclipse UI外配置依赖访问规则?

Automating Eclipse Plugin Access Rules for Internal Classes

Great question—this is exactly the kind of automation that keeps teams from wasting time on repetitive manual setup. Let’s break down the reliable ways to set those access rules via configuration or build scripts, so every developer gets the right setup automatically:

1. Directly Update the .classpath File

The simplest way to share this configuration is to modify your project’s .classpath file directly and commit it to version control. Add an <accessrule> element inside the required plugins classpath entry that grants access to the internal EclipsePlugin class:

<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
  <accessrules>
    <!-- Adjust the pattern to match the exact internal class/package path -->
    <accessrule kind="accessible" pattern="org/eclipse/core/runtime/internal/EclipsePlugin*"/>
  </accessrules>
</classpathentry>

When developers pull this updated .classpath into their Eclipse workspace, the access rules will be applied automatically—no manual setup needed.

2. Use OSGi Manifest Configuration (More Standard for PDE Projects)

Since this is an OSGi project, it’s cleaner to define access rules directly in your MANIFEST.MF file, which PDE will use to generate the correct classpath settings. Add the access rule to your Require-Bundle entry for the bundle containing EclipsePlugin:

Require-Bundle: org.eclipse.core.runtime;bundle-version="3.18.000";visibility:=reexport;accessrules:="org/eclipse/core/runtime/internal/EclipsePlugin*"

This ensures the access rule is tied to your bundle’s dependencies, which is more aligned with OSGi best practices. Commit the updated MANIFEST.MF to version control, and team members will pick up the rule when they refresh their project.

3. Configure via Build Scripts (If Using Gradle/Maven)

If your project uses a build tool like Gradle (with the Eclipse plugin) or Maven (with Tycho), you can embed the access rule in your build script to generate the correct classpath automatically:

For Tycho (Maven):

Add the access rule to the Tycho compiler plugin configuration in your pom.xml:

<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-compiler-plugin</artifactId>
  <version>${tycho.version}</version>
  <configuration>
    <accessRules>
      <accessRule>
        <pattern>org/eclipse/core/runtime/internal/EclipsePlugin*</pattern>
        <kind>accessible</kind>
      </accessRule>
    </accessRules>
  </configuration>
</plugin>

For Gradle:

Modify the Eclipse classpath configuration in your build.gradle to inject the access rule:

eclipse.classpath {
  whenMerged { classpath ->
    def requiredPluginsEntry = classpath.entries.find { it.path == 'org.eclipse.pde.core.requiredPlugins' }
    if (requiredPluginsEntry) {
      requiredPluginsEntry.accessRules.add(new org.gradle.plugins.ide.eclipse.model.AccessRule('accessible', 'org/eclipse/core/runtime/internal/EclipsePlugin*'))
    }
  }
}

Running the eclipseClasspath task (for Gradle) or mvn eclipse:eclipse (for Maven) will generate the updated classpath with the access rule.

Quick Tips

  • Double-check the pattern in your access rule: it must exactly match the internal class’s package path (use * as a wildcard for class names if needed).
  • Commit all modified configuration files (.classpath, MANIFEST.MF, build scripts) to your version control system so every team member gets the setup automatically.
  • If you use Eclipse’s team project setups, you can also include the rule in .settings/org.eclipse.jdt.core.prefs, but the .classpath or MANIFEST.MF approaches are more straightforward for PDE/OSGi projects.

内容的提问来源于stack exchange,提问作者Rick S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:48:27