bndtools Activator bundle - osgi

How can I create a simple bundle with an Activator in bndtools?
It keeps saying that:
The JAR is empty: The instructions for the JAR named com.myproj did not cause any content to be included, this is likely wrong bnd.bnd /com.myproj Unknown Bndtools Problem Marker
Unused Private-Package instructions, no such package(s) on the class path: [com.myproj] bnd.bnd /com.myproj Unknown Bndtools Problem Marker
The way I create this project in Eclipse is:
Create new "Bndtools OSGi project"
Right click, configure - Convert to Maven project
Create Activator.java in package com.myproj.
Add com.myproj to private packages
Set activator to com.Activator
Here is my bnd file:
Bundle-Activator: com.myproj.Activator
Private-Package: com.myproj
My generated jar is empty. Any tips?
P.S.: Here is my eclipse project (exported as a zip-archive) in case it sheds any light on things: https://dl.dropbox.com/u/9162958/scraper.zip

My guess is that "Convert to Maven project" is the trouble. This likely has changed the Eclipse classpath for the project from the bnd default bin folder to 'target/classes'. Can you confirm that it works without converting to maven?
bnd can work with other places for the bin folder, you must set the ${bin} property (preferably in cnf/build.bnd). There are some writeups how to use bndtools with maven. The reason that bnd does not follow Eclipse's settings here is that they are not available without Eclipse and a design goal of bnd is that it builds anywhere: the bnd file must therefore be the final arbiter of information.
Anyway one more tip ... activators are not the right way to build OSGi builds since they are an evil singleton. Declarative services is far superior and we should actually have used a similar mechanism when we designed OSGi.

My setup:
Eclipse Luna 4.4.0 (20140612-0600)
Bndtools 2.3.0.REL-20140510-023245
Here is how I made it work:
I downloaded you exported scraper.zip.
Created and empty workspace in Eclipse.
Imported your project from the ZIP archive into the empty workspace.
The default cnf project was automatically created.
By default, bnd is configured to use the bin directory for compiled *.class files while your Eclipse project is configured to use target/classes. Therefore, I had to change this settings in cnf/build.bnd by adding a single line:
########################
## BND BUILD SETTINGS ##
########################
bin: target/classes
Now, after cleaning and rebuilding the project, bnd creates generated/scraper.jar that contains your Activator.class.
Notes:
You could also adapt your project configuration to use the bin directory instead of target/classes but I assume that you will use Maven later on.
When using bndtools, it sometimes helps when you start with an empty workspace and import your projects one-by-one.
There is a bug in bndtools 2.4 which causes some problems if there are multiple source directories per project. Therefore, I'm still using version 2.3

Related

Kafka Connector - Packacking jars

QUESTION
I am not a maven pro and I got stuck trying to package a Kafka Connector. There are two options for packaging it:
Either you produce a folder with a jar that contains the connector + all the dependency jars - all the kafka-specific jars
Or build a fat jar with all of the dependencies (and I also assume without the kafka-specific jars again, but it is not explicit in the docs).
I am following docs on confluent webpage and the connector I am trying to package is this one on github.
What I tried, after cloning the repo with git, is the following mvn clean package. But this seems to create only a single jar of the original project with the dependencies in mvn cache (~/.m2/repository/).
Google also has link on how to create a fat jar, but I would need somehow to specify which jars I want to exclude from the fat jar.
Thanks
UPDATE
Now I am running:
connect-standalone /etc/kafka/connect-standalone.properties /etc/kafka/connect-cdc-mssql-source.properties
Where /etc/kafka/connect-standalone.properties contains the following line:
plugin.path=/shared_win_files
And ls -al /shared_win_files contains the following:
kafka-connect-cdc-mssql-0.0.1-SNAPSHOT.jar
And jar tvf kafka-connect-cdc-mssql-0.0.1-SNAPSHOT.jar contains the following:
6996 Thu Sep 07 14:47:24 BST 2017 com/github/jcustenborder/kafka/connect/cdc/mssql/MsSqlSourceConnector.class
where MsSqlSourceConnector.classis basically this class here which implements the Connector.
But when I try to run the connector with the command above, I get an error
Failed to find any class that implements Connector and which name matches com.github.jcustenborder.kafka.connect.cdc.mssql.MsSqlSourceConnector
It gives a massive list with all available plugins, but mine is not in there.
Currently, an easy way to package your connector with maven is to use maven-assembly-plugin. This basically entails two main steps:
Define one or more assembly descriptors and save them under src/assembly.
Doc: http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
Example: https://github.com/confluentinc/kafka-connect-elasticsearch/blob/master/src/assembly/package.xml
In the descriptor, among other things, you may choose the packaging format of your archive, files and directories to include or exclude, as well as specific settings regarding your projects dependencies.
Include the plugin in your project's pom.xml
Example: https://github.com/confluentinc/kafka-connect-elasticsearch/blob/master/pom.xml
This mainly requires you to define the configuration and execution sections of the maven-assembly-plugin section. Additionally you can associate calls to specific assembly plugin descriptors with certain maven profiles that you may define.
Finally, stay tuned because packaging your Kafka Connect plugins (connectors, transforms, converters) might be significantly simplified soon.
Following Konstantine's answer how to package jars.
The remaining problem was that when specifying plugin.path=/abc in KafkaConnect config, you have to be careful.
You can either put a fat jar like this:
/abc/fatjar.jar
Or you have to create another folder in abc and put all the related jars into that folder like this:
/abc/my-connector-a/connector.jar
/abc/my-connector-a/connector-dependency.jar
...
As in my case, it was treating jars as separate plugins.

Maven - Wrong folder structure

I have checked in one of my projects to GIT repo. When i cloned it from GIT, imported the project to eclipse and converted the project to Maven Project, the folder structure of maven seems to be a bit different
This should have been src/main/java, src/test/java, src/test/respurces folder structures and com.vod... as package.
I have tried maven>update project, project>clean, maven>clean, eclipse::clean, eclipse::eclipse. But this project structure does not seem to go off.
Any possible solutions for this please?
After importing the project as eclipse general project, below is the structure.
This is a typical problem due to the lack of Eclipse metadata files in the GIT repository.
How to solve it:
Open the project's contextual menu > Java Build Path > Configure Build Path > Source. Drop off folder src and set as folder sources just these:
src\main\java
src\main\resources
src\test\java
src\test\resources
This will save some metadata to the .classpath file.
Also, you should ensure that this was set as a Maven project: Open the project's contextual menu > Configure. If there is the Convert to Maven command, execute it (if not, it is already a Maven project). This might save some metadata to the .project file.
Then, be sure to check in the Eclipse metadata files (.classpath, .project and .settings folder) to GIT. And, in order for this project can be safely shared to other developers, be sure not to enter absolute paths in the java build path, nor other system-dependant constraints.

How to enable jsp-tags autocompletion in NetBeans within NetBeans Maven projects?

Using NetBeans 7.1.2.
When editing pages with NetBeans as per the procedure explained below, the IDE offers only autocompletion for <jsp:...> tags:
This is how I have created the NetBeans project and the jsp (though it isn't archetype specific, nor the issue has anything to do with opencms): I have created a maven project with the OpenCms-Module archetype
mvn archetype:generate -DarchetypeCatalog=http://bp-cms-commons.sourceforge.net/m2repo
The archetype creates a maven project with jar packaging.
After that, I have added a jsp under src/main/opencms/modules/blahblah/templates.
And then I have added the taglibs.standard dependency to the project, to try to provide NetBeans with the corresponding tlds.
After several hours trying to get this working, I found this reported and closed bug that hinted me into the right direction:
Added src/main/webapp directory Edit 1: There is autocompletion only for jstl tags if the files are inside src/main/webapp. Workaround in linux (not sure if windows links will work): Create a symlink:
ln -s opencms/ src/main/webapp from the project root folder
Change maven project packaging to war (Project properties -> General -> Packaging)
(Notice that neither the #taglib directive nor the taglibs.standard dependency are necessary.)
If the Web Pages entry does not appear under your project (in the projects view), you may need to restart NetBeans. Now you'll have full autocompletion (only) under src/main/webapp! :-)
Edit 2
Unfortunately, if under version control, NetBeans sees the symlink as a new directory, and all files under it, as new files :-( This is very inconvenient, because to access the IDE integrated version control functionality, you still need to open the original resource.

How to create a working OSGI bundle for Apache POI 3.8?

My goal is to create an Excel 2007 document (XLSX) in an Eclipse RCP Environment (Excel 2003 is simple). I don't want to place the POI jars inside a /lib folder, instead I want to use a working POI OSGI bundle from my target definition.
All my attempts so far have failed to create a working OSGI bundle of POI 3.8. What I did so far:
I merged all relevant JAR files with the Ant zip task:
poi-3.8-beta3-20110606.jar
poi-ooxml-3.8-beta3-20110606.jar
poi-ooxml-schemas-3.8-beta3-20110606.jar
poi-scratchpad-3.8-beta3-20110606.jar
I ran the bnd tool with the wrap parameter: java -jar biz.aQute.bnd.jar wrap ./poi-3.8-beta3-20110606-merged.jar
I had to bundle the jars in the /ooxml-lib folder separately, with bnd:
xmlbeans-2.3.0.jar
stax-api-1.0.1.jar
dom4j-1.6.1.jar
This leads to ClassNotFoundExceptions for org.w3c.dom.Node because xmlbeans-2.3.0.jar exports four classes from this package org.w3c.dom. Normally the JavaSE-RuntimeEnvironment would export these.
I deleted the org/w3c/dom folder from xmlbeans-2.3.0.jar and rebundled the jar but I got other ClassNotFoundExceptions.
This is where I got so far. I think working with bnd wrap is not enough. Probably I must create a bnd.properties file and have explicit Export-Package/Import-Package statements but which work?
So, has anyone successfully managed to create a working POI 3.8 OSGI bundle?
If you don't need that specific version, simply use http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.apache.poi&version=3.0.2.FINAL that page lists it's dependencies etc (which you can also download or reference if you're using Maven/Ivy)
May be http://engroup.sourceforge.net/maven2/engroup/osgi/commons/poi-osgi/3.1/ or http://ebr.springsource.com/repository/app/search?query=poi can provide some inspiration (in the first link there's a maven POM that lists the (bnd) instructions in the bundle plugin section).
Why are you merging the jars? Why not try wrapping each individually?
A second thing to try is to use existing OSGi'd jars of xmlbeans, stax-api and dom4j
Also you can configure what the JRE (system bundle) exports using "org.osgi.framework.system.packages" - so you can choose not to export org.w3c.dom
I was able to do after some serious head banging. You can see the POM file over here:
http://servicemix.396122.n5.nabble.com/Apache-Poi-3-7-component-tc4912054.html#a5009396
I had to repackage XMLBeans 2.3.0 and embed in the bundle.
Cheers,
Yogesh
I don't know about 3.8, but creating working OSGi bundle for 3.7 is quite easy with Bnd.
-classpath: poi-3.7-20101029.jar,
poi-ooxml-3.7-20101029.jar,
poi-ooxml-schemas-3.7-20101029.jar,
poi-scratchpad-3.7-20101029.jar
Bundle-Name: Apache POI
Bundle-SymbolicName: org.apache.poi
Bundle-Version: 3.7.0
Bundle-ClassPath: .
Private-Package: *
Export-Package: org.apache.poi.*;-split-package:=merge-first
Import-Package: !org.openxmlformats.schemas*, \
!schemasMicrosoftComOfficePowerpoint*, \
!schemasMicrosoftComOfficeWord*, \
junit*;resolution:=optional, \
org.apache.commons.logging;resolution:=optional, \
*
Include-Resource: #poi-3.7-20101029.jar, \
#poi-ooxml-3.7-20101029.jar, \
#poi-ooxml-schemas-3.7-20101029.jar, \
#poi-scratchpad-3.7-20101029.jar
If you are interested in a working example of the approach with BND, you can have a look at this project, providing a pom and a bnd file (inspired by Jarek's answer):
https://github.com/evandor/skysail-bundled-libraries/tree/master/skysail.bundles.poi
Running "mvn install" gives you an "OSGi-flavored" POI jar, which can be found as well here:
https://oss.sonatype.org/content/groups/public/de/twentyeleven/skysail/org.apache.poi-osgi/3.8/
You might have to play a bit with the bnd file to make it create the exact OSGi bundle you need (maybe you don't need all the dependencies, or you want to mark them as optional).
You will find all the documentation needed on the bnd homepage. I recommend starting with this page if you haven't used this great tool before.

How to add OSGi WAR bundle ine eclipse target platform

For my OSGi development i have setup a target definition (.target file) which references two directories. Eclipse picks up all the jar files inside these directories and adds them to the target platform. But one of the bundles i have is a WAR file (.war extension) which is run using pax-web. Eclipse doesn't show this in the list of bundles available. Is there any way to add a particular bundle directly into the target definition? Any way out that i might be missing?
One workaround i found was to rename the .war file to .jar. Pax-web doesn't care about the extension, eclipse picks it up and so everything runs fine. But i am not very convinced if this is the right solution.
Thanks.
Bug 355890 was fixed for 3.8/4.2. You can now include archive files that are not jars (i.e. WAR files).
There is a known bug filed on eclipse on this very issue. Until it is fixed, the only workaround is to rename the file to have the .jar extension.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=355890

Resources