简体   繁体   中英

Ant: get Java class name and write to properties file

I would like to automate my OSGi manifest creation with the help of the bnd tool. For this, I need to create a properties.bnd file with the following two lines:

Bundle-Activator=org.company.package.MyPluginActivator
Export-Package=org.mycompany.package #or possibly multiple packages here

My automation script would need to find a java class which implements the BundleActivator interface, in this case it is org.company.package.MyPluginActivator . As well as it's package name, which is org.company.package in this case.

Ideally, I would like to automate this with Ant, but happy with any other lightweight and cross-platform tool that does not require previous installation.

Thanks!

PS: I am aware of the Ant Property and PropertyFile Tasks, but would not know how to get the name of the required java class.

What if you have multiple BundleActivator implementations in your bundle?? Are you really happy with a tool deciding, essentially at random, which one will be the main entry point of your bundle??

I feel that you are missing the point of the bnd file, which is to be your description of the content of the bundle. That is, it is a source file that you should write.

Also, why do you want to export the package that contains the bundle activator? This package should be private in OSGi.

The problem is that, as Neil indicated, there can be multiple classes implementing BundleActivator. This is one of those wonderful ways to to waste a couple of hours 6 weeks from now figuring out why your code stopped working ...

Anyway, since you seem to be insistent on shooting yourself in the foot you can also do:

Bundle-Activator: ${classes;implements;org.osgi.framework.BundleActivator}

Which seems a lot easier than doing the accepted answer, and will at least generate an error when there are actually multiple implementers.

Anyway, you also commit another mortal sin (in the OSGi world) by exporting the package that contains your activator. The whole idea of OSGi to keep stuff private (You should use Private-Package for this).

Using reflection you can write a program to get the classname implementing the desired interface.

Call that java program using Ant Java Task . (I recommend using a separate JVM to run this task you can find the settings on the link provided)

The program written in the first step can also be used for writting values to the property files so Property Task is not needed.

Let me know for any further clarification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM