I'm developing an OSGI bundle which uses the native library librxtxSerial.
The first time, I had to deploy this bundle on a raspberry, so I've did something like that:
I put the native library under: lib/librxtxSerial.so (NB: INSIDE the java project).
Then, in the MANIFEST I've wrote:
Bundle-NativeCode: lib/librxtxSerial.so
Everything works fine!!!
Now, the problem is that I've to deploy the same bundle on other embedded device which uses a different processor architecture (x86 instead ARM).
So, I've downloaded the x86 build for the librxtxSerial library and I modified my folder structure in something like that:
- lib
- x86
- librxtxSerial.so
- arm
- librxtxSerial.so
And I've modified my MANIFEST in this way:
Bundle-NativeCode: lib/x86/librxtxSerial;processor=x86, lib/arm/librxtxSerial;processor=ARM_le
Trying to compile (through maven tycho plugin) I always get the same error:
No match found for native code: lib/x86/librxtxSerial; processor=x86, lib/arm/librxtxSerial; processor=ARM_le
How can I solve this?
Ok, i've solved. Not sure why but in order to solve this issue is enough to add '*' at the end of the header, so:
Bundle-NativeCode: lib/x86/librxtxSerial;processor=x86, lib/arm/librxtxSerial;processor=ARM_le, *
it now works.
I'm using fabric8-karaf-1.1.0.CR5 in a stand-alone installation and it works fine there.
Now I wanted to embedd it into Eclipse Kepler SR2.
I basically followed Integrating Felix with Eclipse. But, instead of just adding bin/felix.jar to the project's build path as in Figure 8 I added all jars of lib and its sub-directories bin and endorsed (after a lot of errors were thrown at me by just adding lib/karaf.jar).
There are still three issues:
The following is printed to System.err:
Jul 28, 2014 12:12:24 AM org.apache.karaf.main.SimpleFileLock lock
Information: locking
What does this error(?) message try to inform me of? That a file named lock is created in the project's root directory? Thank you, but why?
The following is printed to System.err:
Error in initialization script: \shell.init.script
(The system cannot find the file specified)
The parenthesized is the Windows version of a FileNotFoundException's detail message. There exists an etc\shell.init.script and for the sake of the directory not mentioned I copied it to the project's root folder, to no avail.
I had to comment the following bundles in etc\config.properties:
#org/apache/sshd/sshd-core/0.9.0/sshd-core-0.9.0.jar=30
#org/apache/karaf/shell/org.apache.karaf.shell.ssh/2.3.0.redhat-610379/org.apache.karaf.shell.ssh-2.3.0.redhat-610379.jar=30
#io/fabric8/fabric-zookeeper/1.1.0.CR5/fabric-zookeeper-1.1.0.CR5.jar=39
#io/fabric8/fabric-api/1.1.0.CR5/fabric-api-1.1.0.CR5.jar=40
#io/fabric8/fabric-agent/1.1.0.CR5/fabric-agent-1.1.0.CR5.jar=40
#io/fabric8/fabric-core/1.1.0.CR5/fabric-core-1.1.0.CR5.jar=45
#io/fabric8/fabric-boot-commands/1.1.0.CR5/fabric-boot-commands-1.1.0.CR5.jar=45
#io/fabric8/fabric-commands/1.1.0.CR5/fabric-commands-1.1.0.CR5.jar=50
#io/fabric8/fabric-configadmin/1.1.0.CR5/fabric-configadmin-1.1.0.CR5.jar=50
... to get rid off errors of the form:
ERROR: Bundle <Bundle-SymbolicName> [<ID>]
Error starting mvn:<bundle-path> (org.osgi.framework.BundleException:
Unresolved constraint in bundle <Bundle-SymbolicName>:
Unable to resolve <ID>.0: missing requirement [<ID>.0] osgi.wiring.package;
(&(osgi.wiring.package=<Other Bundle-SymbolicName>)(<versions>))))
... but with these bundles disabled Fabric8 shuts down immediately.
It's right, the few missing bundles I have checked aren't in my local .m2 repository. But Maven works well with all other projects, in and out of Eclipse. Go on Fabric8, download them!
What am I missing?
I want to replace the auto injected log object, which is of type org.apache.commons.logging.Log with an object of type org.slf4j.Logger, so that I can use it properly with Logback.
Therefore I need to create a ...Transformer class (written in Java) - that's what I got from Graeme Rocher over at the "grails-user" mailing list. I'm also aware that I have to pack this ...Transformer class within a plugin and make it a *.jar archive which I can load within the lib/ folder of the plugin. But I guess I'm doing something wrong here as I have the class, along with a META-INF folder which contains the MANIFEST.MF file as well as another folder services which holds the following file org.codehaus.groovy.transform.ASTTransformation which holds just one String: the canonical name of the ...Transformer class.
Now, if I try to do a grails clean everything is fine, BUT if I try to run grails package-plugin the console comes up with a java.lang.ClassNotFoundException.
Clipping from Stacktrace:
| Packaging Grails application...
| Error Fatal error during compilation org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Could not instantiate global transform class my.package.ast.LoggingTransformation specified at jar:file:/C:/Source/MyGrailsAST/lib/replace-logging-logback-ast.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.ClassNotFoundException: my.package.ast.LoggingTransformation
1 error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Could not instantiate global transform class my.package.ast.LoggingTransformation specified at jar:file:/C:/Source/MyGrailsAST/lib/replace-logging-logback-ast.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.ClassNotFoundException: my.package.ast.LoggingTransformation
Does anybody have some experience with Grails plugins which handle with AstTransformer and could give me some advice on this? Is there a good tutorial out there which I haven't seen so far?
Please let me know ;)
so, after some research, browsing and finally asking at the Grails Mailing List (see the mailing list archives at: http://grails.1312388.n4.nabble.com/Grails-user-f1312389.html I found a solution.
my goal was to create a Globals ASTTransformation, to inject a org.slf4j.Logger object instead of the usual org.apache.commons.logging.Log object into every Artefact class without annotation.
so, here are the steps:
I created Java class similar to https://github.com/grails/grails-core/blob/master/grails-logging/src/main/groovy/org/codehaus/groovy/grails/compiler/logging/LoggingTransformer.java but with my own implementation of the org.slf4j.Logger object. It is crucial that you place the Java.class under the following package: org.codehaus.groovy.grails.compiler as
Grails scans for classes that are annotated with #AstTransformer in this package. (Graeme Rocher)
and pack it into a JAR along with its MANIFEST.MF file within the META-INF/ folder. A META-INF/services directory with all its stuff is not needed as Graeme Rocher stated:
You do not need the META-INF/services stuff and I would remove it as it is probably complicating matters.
So, I guess this statement was more related to my specific problem as I only have one #AstTransformer class within my plugin, but that's just a guess. And I haven't searched for further informations on this topic. Maybe some other developer here who needs this could do some research and share his solution within this thread...
The JAR should be imported to the plugin and placed under the lib/ directory. After this you should be able to do grails clean, grails compile and grails package-plugin.
If you want to replace the log implementation, as I did, you should exclude the grails-logging and grails-plugin-log4j JARs from your designated project's classpath. This is done in the BuildConfig.groovy file:
inherits("global") {
excludes "grails-plugin-log4j", "grails-logging"
}
Now install your plugin grails install-plugin \path\to\plugin.zip and everthing should work as expected.
Hope this helps...
I have a Java (6) application which uses Hibernate (V3.3.2) to read data from HSQLDB, which i build and debug/run with Eclipse (V3.5.1), and it works fine.
I then created a GWT (V1.7) Servlet web app, copied my hibernate classes into it, and added the same User Libraries dependencies. However when i run the servlet and try to access a URL which invokes my code i get this:
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
at xxx.daoimpl.DAOSession.initialise(DAOSession.java:40)
where DAOSession.java:40 is :
AnnotationConfiguration config = new AnnotationConfiguration ();
Googling for this error suggests i am missing slf4j-api.jar from the classpath, however if i look at the command line for the Debug properties i can see this jar there:
C:\java\jsedk_6\jre\bin\javaw.exe
-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:54541
-Xmx512m -Dfile.encoding=Cp1252
-classpath
D:\dev\workspace\xxx\src;
D:\dev\workspace\xxx\resources;
D:\dev\workspace\xxx\war\WEB-INF\classes;
C:\java\eclipse\plugins\com.google.gwt.eclipse.sdkbundle.win32_1.7.1.v200909221731\gwt-windows-1.7.1\gwt-user.jar;
C:\java\eclipse\plugins\com.google.gwt.eclipse.sdkbundle.win32_1.7.1.v200909221731\gwt-windows-1.7.1\gwt-dev-windows.jar;
C:\java\hibernate-annotations-3.4.0.GA\hibernate-annotations.jar;
C:\java\hibernate-annotations-3.4.0.GA\lib\ejb3-persistence.jar;
C:\java\hibernate-annotations-3.4.0.GA\lib\hibernate-commons-annotations.jar;
C:\java\hibernate-distribution-3.3.2.GA\hibernate3.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\antlr-2.7.6.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\commons-collections-3.1.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\dom4j-1.6.1.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\javassist-3.9.0.GA.jar;
C:\java\hibernate-distribution-3.3.2.GA\lib\required\jta-1.1.jar;
C:\java\hibernate-validator-4.0.1.GA\hibernate-validator-4.0.1.GA.jar;
C:\java\hibernate-validator-4.0.1.GA\lib\validation-api-1.0.0.GA.jar;
C:\java\hibernate-validator-4.0.1.GA\lib\log4j-1.2.14.jar;
C:\java\hsqldb\lib\hsqldb.jar;
C:\java\restlet-jse-2.0m5\lib\org.restlet.jar;
C:\java\restlet-jee-2.0m5\lib\org.restlet.ext.servlet.jar;
C:\java\restlet-jse-2.0m5\lib\org.restlet.ext.xml.jar;
C:\java\slf4j-1.5.8\slf4j-api-1.5.8.jar;
C:\java\slf4j-1.5.8\slf4j-log4j12-1.5.8.jar
com.google.gwt.dev.HostedMode
...
If i open the jar i can see the LoggerFactory class in there.
Any idea why it isn't being found by the class loader?
Edit 1: If try to access org.slf4j.LoggerFactory from my code, Eclipse compiles it ok, but i get the same error at runtime.
Edit 2: If i add a Test class with a main which calls the same code and run it, it works. So this classpath problem seems specific to the Servlet.
thanks,
jon
It seems that copying the two slf4j jars to the war/WEB-INF/lib sub-project/dir fixed the problem. I'm not really sure why i should need to do this for these two jars and not for all the other Hibernate, Restlet etc jars that the project also uses, though i suppose for consistency i will do that anyway - i guess it will make deployment easier as well.
If someone can provide some sort of explanation as to why this worked and why exactly i need to do it i will select it as the "correct" answer, otherwise i'll select this one.
Can you please reconfirm that you have at least two slf4j.jar files in the classpath, the slf4j-api.jar and exactly one implementation, such as slf4j-jdk14.jar?
You must not have multiple sflj4-implementations in the classpath.
You have a runtime dependency issue so everything compiles fine but the dependency is in your jars. You need to visit the Hibernate site and look at the compatibility matrix and make sure you are matched up correctly then check the dependencies for annotations and core. You log4J jars look fine so it's definitely some quirk.
If it works in Eclipse then logically it's definitely some diff between the 2 runtimes (eclipse and non-eclipse), if the matrix checks out fine then see if you can factor out the commonalities in the 2 then work out the differences -- your answer should be in there.
I had a similar issue except I was using Tomcat and the NoClassDefFound error was on the juli logger. I fixed it by removing the Tomcat dependencies from my classpath when running in hosted mode because hosted mode embeds a Tomcat server that was conflicting. So I would see what happens if you remove some or all of the restlet jars from your classpath to see if they conflict.
I'm trying to create a simple plugin in eclipse. When I run the application, I see this error in log file:
org.osgi.framework.BundleException : The activator for bundle
org.x.y.Activator for bundle org.x.y is invalid.
Do you have any idea about this error?
Check your build.properties section
If it doesn't properly specify what's supposed to be in the final binary result, it will not work. Check the .class files are where the MANIFEST.MF says they will be.
from EclipseZone, another reason for this error message:
If you see a message in the log like
The activator org.example.FooActivator for bundle org.example.foo is invalid
, then this usually means there has been a ClassNotFoundException trying to load the class in the first place, before it's even got to the start() method.
penguru adds:
The error occurs when I try create a new object from any other class in the constructor of activator class. Isn't it legal to create an object in activator plugin ?
If that class if from another plugin which has not yet been "activated", that could be your problem.
If that class is not found, that would also invalidate your plugin activator.
Basic advice: you may be better off with your initializations done in the start() method of Activator rather than its constructor.
I also faced same issue while importing plugins from different workspace. Basically, it is the bundle classpath where the framework looks for while loading the classes. When you import to a different workspace, make sure you change the class path to point to appropriate location i.e. where the class file are present.
After modifying the classpath try to clean and re-build and re-run. It should work..hopefully..
OK, I hate to be captain obvious here, but I've made this mistake before. This can also happen when you forget to extend BundleActivator.
If you have move the eclipse workspace to a new path, then you should use the project->clean before your plugin build, Or you would meet this problem.
I spent some time with this problem. Finally I noticed that the ClassNotFoundExceptions were not in line with my code, they were coming from wrong (old) packages. I checked if there was some other plugin which was messing with my debugs/exports and indeed there was, my own plugin!
So a simple fix to try if you're facing this and the CNFE's are not in line with your code:
Go to "Install new software"
Click on "already installed"
Remove all instances of your package/plugin and restart
Likely this was caused because I changed the plugin ID, making Eclipse treat it as a new plugin.
Another good site to take a look if you're getting frustrated and stuck: http://www.eclipsezone.com/eclipse/forums/t99010.html
In my case there was this Message "Activator ..invalid" but in the next exceptions there were ClassNotFound Exceptions in a Bundle were i didnt change something..
Guu(Posted a solution too) is my hero, After increasing
Bundle-ManifestVersion: 2
to
Bundle-ManifestVersion: 3
everything works :)
I got the same exception. The underlying problem was a ClassCastException. My bundle requires org.osgi.core 4.3 whereas the equinox launcher uses 4.2.
Regards
Roland
This can also happen if you name a bundle after a package in another bundle.
So:
if you have Bundle A which contains package org.my.package.name.function,
and you create bundle B with name org.my.package.name.function,
=> then the system may look for the activator there, and not find any.
I found the reason of the error. The error occurs when i try create a new object from any other class in the constructor of activator class. Isn't it legal to create an object in activator of plugin ?
In my case this exception was because of inability of Eclipse custom class loader to resolve and load all depending classes from other plugins in-time. I am not Eclipse super-guru so maybe it was my fault.
However it was fixed by disabling lazy loading of plugin. In GUI on Overview tab of MANIFEST.MF editor uncheck Activate this plug-in when one of its classes is loaded. Or directly in MANIFEST.MF delete line
Bundle-ActivationPolicy: lazy
Another captain obvious: If you change the paths of your source files (e.g. src/ to src/main/java), but forget to update build.properties, the compilation will always succeed, but your plugin will never work.
I had the same error, in my case I created my own constructor with parameters. But I didn't provide a default constructor. So after removing my constructor and initialized all within the start() method, it worked like charme.
I also met the same error. The activator XX for bundle XX is invalid, and the ClassNotFoundException.
I checked plugins\ directory, and could not find the class needed.
--
Because there is no jar file containing the needed class, there is only the corresponding directory.
For example, there is no com.hh.jar, but only com.hh directory.
So, there must be something wrong about creating the com.hh.jar.
if com.hh.jar reference other plugins, then also check them.
I solved the problem by editing MANIFEST.MF.
Open it by Plug-in Manifest Editor, in runtime tab, add needed packages in "Exported Packages".
and in the "classpath", add needed libraries, and, "." (current directory, IMPORTANT)
I have also run into this isue when 'bundle-izing' plain jar files. If some dependencies are not resolved, or jars depend on a higher JAVA version than the one you're using, the activator will not start, giving the above exception. The quick way to find out if this is the problem is to remove the jars from the bundle-classpath (runtime tab of the manifest) and check if the activator will run correctly.