How to ensure eclipse plugin has required bundles available? - eclipse-plugin

I'm just starting to develop a new eclipse plugin where I want a web application server running in Eclipse. I found a nice blog, OSGi as a Web Application Server, that describes how to do this. The author suggests creating a target environment for my bundle requirements, and some of those bundles get pulled in from the Equinox Project SDK (now called Equinox Target Components in Juno). I notice that the tutorial project runs fine when my target platform is the platform I created in the tutorial, but fails to start when it is the default platform. So, now for my question...
If I need bundles that are not part of the default, how will my plugin project get access to those bundles? Will I need to deploy them along with my plugin? How would I know if the user's eclipse does or does not already have those required bundles?

You was not much clear about what kind of application you are developing. Running a web server in an Eclipse IDE as a plugin don't make any sense to me. This kind of server application is best just running on top of Equinox.
Anyway, the right path is to create a "Product Configuration" file and add categories that contains the needed bundles (go to File/Plug-in Development/Product Configuration).
With this file you can run an instance of the product (inside the IDE) and can export it (create a zip containing all needed bundles)
And if you want to able your user to install plugin inside his IDE you must create a P2 repository (using a Target Definition File) and expose the exported directory within a Http server. You could research about Tycho to build this kind of components in a maven style.

Well, I'm not sure if re-inventing the wheel again is really sufficient.
You might take a look at Pax-Web for inspiration on how to do it, or take a look Apache Karaf as a OSGi-Container (using Pax-Web). Or even better start contributing to one of the two :-)

Related

Change IBM Worklight project path

I need to create a Hybrid Worklight project but it needs to be physically inside another project.
The reason is that we are using an API that generates a project using grunt and the guide I got (company standards, practices, etc) says: Once the project is in Eclipse, create a wl folder and create the Worklight project inside of it.
When I create a new Worklight project in Eclipse it always goes to Eclipse's Workspace folder. How can I change this?
Thanks
You cannot (at least, not in a standard/supported/known working way); a Worklight project contains Worklight applications but cannot contain other Worklight projects. Worklight projects are always contained directly within an Eclipse workspace (unless working with the CLI tools).
Based upon your clarifying comment, it seems that your containing "(general) project" is just another directory that contains a wl directory - not a real Eclipse project - that in turn contains your Worklight project. It seems you are creating the whole thing using the CLI tools.
In order to work with this project within Eclipse, you'll need to create a new Eclipse workspace elsewhere (the Eclipse workspace itself isn't particularly important and doesn't necessarily need to saved in source control). You can then use File->Import->Existing Projects into Workspace to import the Worklight project from the wl directory. You can either "Copy projects into workspace" (in which case you will end up with two copies), or leave that unticked, in which case your Eclipse workspace directory will just contain a reference to the original directory (I suspect you want the latter).
As a word of advice, generally you should try not to work with both Eclipse and the CLI tools at the same time. Although it may work, you will get conflicts with (for example) the embedded test server, and long term, you'll just cause confusion.
Edit: looks like Andrew says pretty much the same.
Using Eclipse, since what you see in the Project Explorer view is the workspace Eclipse uses, it makes sense to me that when you create a Worklight project in Eclipse, it will be located - in the filesystem - inside the workspace.
If you want to create your Worklight project elsewhere, you'll probably need to use the Worklight CLI tool. From a terminal, navigate to the location of the Grunt project and then, using the CLI commands, generate a Worklight project in that location.

Integrate Apache ACE with Equinox

I've read in the documentations of Apache Ace 2 that it works with Equinox OSGi targets as well, but I can't find out how to configure it. I am aware there is already p2 for Equinox but I also want to integrate it with the Ace software.
I've found somewhere that I should edit managementagent bundle, if that's true still don't know how.
The binary release of Apache ACE ships with:
An executable jar that contains Apache Felix and the management agent. It can be found in the server-allinone/store folder and is called ace-launcher.jar
A "development" target in the target/ folder that can be used to for development/testing and pre-installs a shell, logging and the management agent.
Neither gives you Equinox out of the box.
However, if you checkout the ACE sources, there is a project called org.apache.ace.agent.launcher which creates two jar files:
felix.bnd which creates the ace-launcher.jar mentioned above and embeds Apache Felix
base.bnd which relies on the standardized launcher API of OSGi and will bootstrap the first framework it finds on the classpath
So, you can either use the artifact generated by base.bnd and put Equinox on your classpath, or take felix.bnd and modify it so it will run equinox instead.
By the way, we would be happy to accept such work as a patch so we can provide this out of the box.

Importing Cordova plugins into Worklight 6

I worked through the ApacheCordovaPlugin example. Its nice to see that creating a new plugin is possible, and I successfully replicated the HelloWorldPlugin in a WL project of my own just to make sure I could get all the plumbing to work. It is tricky, you have to make entries in the right XML files, name your Java and .js files appropriately, know how to include them and call the functions, etc. If you make a mistake there is very little information visible that you can use to debug it. The entire process is very fragile.
Now I would like to have access to the large library of existing Cordova plugins. My primary development target is Android. I downloaded a plugin zip file from a git repository and extracted it. Looking at the files and the directory layout it is not at all clear how to integrate this into a WL project. Cordova has a 'plugin.xml' file that appears to supply all the glue, but there is no such thing in WL. I was not able to determine where to put files and what edits to make in the Worklight project that would cause the Cordova plugin to be recognized and accessed from my application JavaScript.
Surely this process is possible and is documented somewhere? Ideally there would be a utility that we use to import Cordova plugins, but next-best would be a step-by-step procedure description. I saw one somebody did for getting plugins into the iOS application environment, but not Android.
Most probably you've downloaded a plugin for cordova 3.0+. Since latest WL contains Cordova 2.6 you need to download plugin for this (or similar) version. E.g. if you're talking about barcode scanner plugin the most suitable version would be 2.2 (https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner)

How do I get a plugin with platform specific code to deploy to the correct platform using an eclipse p2 repository?

I have an Eclipse Feature that I'm building that contains a few plugins. One of the plugins uses the import package statement to declare a dependency on another plugin.
The other plugin has platform specific code and exists in another feature that I'm building. I have two plugins in this feature that have the platform specific code. One for os=win32 arch=x86 and the other for os=win32 arch=x86_64
Both features are being built and using Tycho and they both have p2 repositories that are successfully available.
So, I made a composite repository that points to both of these repositories, and then I use the "Install New Software..." command in my RCP app and point to the composite repository to install the first feature I mentioned.
The issue is that when the installation is done, the plugin that has the platform specific code has failed to install correctly. Specifically, the plugin for the x86 system shows up on my 64bit machine.
In your feature.xml, choose the plugin with platform specific code and add a platform filter. the filters are available on the right side (once you select the plugin). You can choose filters such as:
OS
WS
Language
Architecture
When your feature is published, p2 will generate the appropriate filters.
I found the answer.
I needed a p2.inf file sitting next to my feature.xml file in the first feature I mentioned in the question.
And in that p2.inf file, I needed this text...
requires.1.namespace=org.eclipse.equinox.p2.iu
requires.1.name=com.myplatform.specfic.bundle.win32.x86
requires.1.filter=(&(osgi.os=win32) (osgi.arch=x86))
requires.1.namespace=org.eclipse.equinox.p2.iu
requires.1.name=com.myplatform.specfic.bundle.win32.x86_64
requires.1.filter=(&(osgi.os=win32) (osgi.arch=x86_64))
I added this file to the build.properties as well to make sure it was included in the deployed feature
Then when I deployed the p2 repository and performed the install into my RCP application, the correct plugin was placed onto my 64 bit machine.
UPDATE: I was wrong here. This is NOT the correct answer. The incorrect plugin still gets installed on some machines.

Is this the right approach for structuring codebase?

We have a Java codebase that is currently one Web-based Netbeans project. As our organization and codebase grows it seems obvious that we should partition the various independent pieces of our system into individual jars. So one Jar library for the data access layer, one for a general lib, one for a specialized knowledge access, etc. Then we'd have a separate project for the web application, and could have one for a command line tools app, another web app eventually, etc.
What is the recommended practice for doing and managing this? Is it Maven? Can it all be effectively done with just Netbeans alone by simply creating individual projects and setting the dependecies of one project on the jar files of the others?
I'd agree with SteveG above on using Maven2 to help you modularise your code base, but I'd use Nexus as the local repository for Maven instead of Archiva. The guys at Sonatype also have an excellent (free html/pdf) book on how to use Maven, Nexus, and integrate it into IDEs.
Be careful on how you decide to partition up your projects, though. There's no sense in over-complicating your dependencies just for the sake of it.
I would definitely say check Maven(2) out. It is very good for doing this sort of thing. You can define individual models and version then very easily. Netbeans also does a decent job of integrating with.
Also I suggest you set up Archiva which will let you be dependent upon binaries of other artifacts that your company generates internally. This also acts as a proxy and will keep a local copy of any external dependencies your projects might have so its very quick to get the new versions internally.
I would create ant scripts to build the pieces and for deployment. Then you are not depending on your IDE for build/deployment.
It sounds like your code is getting to the point where you're graduating from the WAR approach and have entered into the EAR level.
An EAR is just another archive that contains all the other JARs and WARs that get combined to create an application. There are four types of modules that can reside inside it, Web, EJB, Connectors and Utilities. Most people only use Web and Utilities so they go with using the WEB-INF/lib approach.
But if you're starting to get a lot of interdependencies what you do create an EAR project and make your web project a child of it. Each Utility JAR which is just straight Java code used by other modules also becomes a child of the EAR. Finally in each of your projects there should be a META-INF/manifest.mf file that just has the name of the JARs that JAR/WAR depends on.
I'm an eclipse guy and most of this gets taken care of for you in eclipse, but I'm sure netbeans has very similar functionality.
Now the only problem is that you have to use a full Java EE server to deploy an EAR so I don't think you can use Tomcat if that's what you're currently using.