How to Add custom JAR to the “eclipse-pmd” plugin?

谁说我不能喝 提交于 2019-12-04 13:50:07

You can use your custom rule classes if you add your jar as an Eclipse plug-in fragment to your Eclipse installation. The host of the plug-in fragment must be ch.acanda.eclipse.pmd.core.

To convert the jar to a plug-in fragment you have to modify the file MANIFEST.MF file and add a few manifest headers. The following is a complete manifest of an Eclipse plug-in fragment:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Custom PMD Rules
Bundle-SymbolicName: org.example.customrules
Bundle-Version: 1.0.0
Fragment-Host: ch.acanda.eclipse.pmd.core;bundle-version="1.4.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7

You can choose your own values for the headers Bundle-Name, Bundle-SymbolicName and Bundle-Version. The value of the header Bundle-ManifestVersion must be 2. Fragment-Host must contain the symbolic name of the host bundle ch.acanda.eclipse.pmd.core and optionally the version of eclipse-pmd you have installed. Bundle-RequiredExecutionEnvironment specifies the minimum execution environment the plug-in fragment requires. Its value is JavaSE-1.7 if you compiled it with Java 7 or JavaSE-1.8 if you used Java 8.

Once you changed the manifest of your jar you can copy it into the folder dropins of your eclipse installation. Your plug-in fragment is installed when you start Eclipse.

Finally figured it out myself !

(I should've got it working in my previous attempt itself, but due to a stale custompmd.jar because of failed ANT task, it didn't work that time).

Step-by-step:

  1. Copy the ch.acanda.eclipse.pmd.core_<blahblah#>.jar from plugins directory into a temp directory.
  2. Open the JAR in temp directory using 7-Zip software
  3. Add custompmd.jar into the lib directory.
  4. Edit META-INF/MANIFEST.MF file, append this string ,lib/custompmd.jar at the end of Bundle-Classpath:
  5. Close 7-Zip (and accept the Save dialog).
  6. Take a backup of the existing /plugins/ch.acanda.eclipse.pmd.core_<blahblah#>.jar and replace it with this temp jar.
  7. Exit Eclipse and Restart
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!