NoClassDefFoundError in jackcess - java

I am working on an RCP application which is based on eclipse plugins. In one of my plugin project I add another plugin project as dependency. Let say Project A has Project B as a dependency defined under its manifest. Project B contains jackcess.jar file as referenced library.
In Project B I have a class called Mirror.java
public Mirror(String source, String template, String target) throws SQLException, IOException {
this.sourceString=source;
this.templateFileString=template;
this.targetFileString=target;
}
inside from project A when I try to create an object of class Mirror
Mirror m = new Mirror(connectionString, "EABase_JET4_empty.eap",platformDB.getAbsolutePath());
I get the following error
java.lang.NoClassDefFoundError:
com/healthmarketscience/jackcess/ImportFilter
build.properties of Project B (containing jackcess.jar)
bin.includes = META-INF/,\
src/main/resources/lib/jackcess-1.2.6.af3.jar
The MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MirrorDbToEap
Bundle-SymbolicName: MirrorDbToEap
Bundle-Version: 1.0.0
Export-Package: .,
com.example.jetdb.mirror
Require-Bundle: CommonsIo;bundle-version="2.0.0",
org.apache.commons.lang;bundle-version="2.6.0",
org.apache.commons.logging;bundle-version="1.0.4"
Anyone having any idea what's going wrong here?
Thanks

You are not including the jackcess.jar in the bin.includes in the build.properties file so it is not being included in the RCP build.
Open the build.properties editor and select the jar in the 'Binary Build' selection.
The jar must also appear in the Bundle-ClassPath in the MANIFEST.MF. In the manifest editor in the Runtime tab add the jar to the 'Classpath' section (you should also have '.' for normal plugin code).

It seems the class which is available in compile time, is not available in run time.

Related

How do I configure dependabots in an Eclipse plugin project so that not only the pom.xml is updated but also MANIFEST.MF and build.properties?

I've been using dependabots with github with some degree of success on typical maven projets, as it sends correct pull requests updating the versions of the dependencies in the pom.xml.
On an Eclipse plugin project however, the dependencies and their versions are also listed in 2 other files MANIFEST.MF and in build.properties.
Example build.properties :
bin.includes = META-INF/,\
.,\
plugin.xml,\
lib/,\
plugin.properties,\
lib/nexus-indexer-lucene-model-2.14.20-02.jar,\
lib/jaxb-api-2.3.1.jar,\
lib/activation-1.1.1.jar,\
lib/jaxb-impl-2.3.3.jar,\
lib/jaxb-runtime-2.3.3.jar
Example MANIFEST.MF :
Bundle-ClassPath: lib/cvsclient-20060125.jar,
lib/maven-scm-api-1.9.4.jar,
lib/maven-scm-provider-accurev-1.9.4.jar,
lib/maven-scm-provider-bazaar-1.9.4.jar,
lib/maven-scm-provider-clearcase-1.9.4.jar,
lib/maven-scm-provider-cvs-commons-1.9.4.jar,
lib/maven-scm-provider-cvsexe-1.9.4.jar,
lib/maven-scm-provider-cvsjava-1.9.4.jar,
lib/maven-scm-provider-git-commons-1.9.4.jar,
lib/maven-scm-provider-gitexe-1.9.4.jar,
lib/maven-scm-provider-hg-1.9.4.jar,
lib/maven-scm-provider-integrity-1.9.4.jar,
lib/maven-scm-provider-jazz-1.9.4.jar,
lib/maven-scm-provider-local-1.9.4.jar,
lib/maven-scm-provider-perforce-1.9.4.jar,
lib/maven-scm-provider-starteam-1.9.4.jar,
lib/maven-scm-provider-svn-commons-1.9.4.jar,
lib/maven-scm-provider-svnexe-1.9.4.jar,
lib/maven-scm-provider-synergy-1.9.4.jar,
lib/maven-scm-provider-tfs-1.9.4.jar,
lib/maven-scm-provider-vss-1.9.4.jar,
lib/plexus-utils-3.0.16.jar,
lib/nexus-indexer-lucene-model-2.14.20-02.jar,
lib/nexus-restlet1x-model-2.9.2-01.jar,
lib/maven-scm-provider-jgit-1.9.4.jar,
lib/jaxb-api-2.3.1.jar,
lib/jaxb-impl-2.3.3.jar,
lib/jaxb-runtime-2.3.3.jar,
lib/activation-1.1.1.jar,
.
I use a minimalist dependabots.yml suited for maven :
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
Dependabots sent a pull request "Bump nexus-indexer-lucene-model from 2.14.20-02 to 2.15.1-02" but the pull request only updates the version in the POM, which makes the build fail, because the other files MANIFEST.MF and build.properties were not updated.
How do I get depandabots to update these 2 files MANIFEST.MF and build.properties ?

.bnd files have errors when building in IntelliJ

When I'm building my project in IntelliJ, I get errors for each of my .bnd files (I have no other types of errors).
I started working on a new project which works without any problems for my colleagues (which are too busy to help me do the setup).
What I've done so far:
- got the code and imported it as a maven project in IntelliJ (no errors)
- clean installed it from terminal (no errors)
- build the project from IntelliJ (425 errors - around 2 per .bnd file)
- I tried disabling the OSGi plugins (dmServerSupport and Spring OSGi)
- I tried disabling the Inspection OSGi profile
- I tried adding the file in the Compiler -> Excludes (still builds it)
What can I do to get rid of all those errors?
My OSGi Manifest (from looks like this:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Goodies
Bundle-SymbolicName: com.....osgi.goodies
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: ...
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.osgi.framework;version="1.7.0",
org.osgi.service.component.annotations;version="1.2.0",
org.osgi.service.event;version="1.3.0",
org.osgi.service.packageadmin;version="1.2.0"
For example, I have this .bnd file:
-classpath: target/classes
-dsannotations: *
Include-Resource: README.HTML
Private-Package: com.....pubsub.impl
Export-Package: com.....pubsub
-dsannotations: *
For the file from above, I'm getting the following errors:
Error:osgi: [pubsub] Invalid Manifest header: -classpath, pattern=[A-Za-z0-9][-a-zA-Z0-9_]+
Error:osgi: [pubsub] Invalid Manifest header: -dsannotations, pattern=[A-Za-z0-9][-a-zA-Z0-9_]+
Another example:
-classpath: target/classes
-dsannotations: *
Include-Resource: README.HTML
Private-Package: com.....security.thread.impl
Export-Package: com.....security.thread
Import-Package: oracle.jdbc;version=0,\
*
Building the project containing the .bnd file from above, will result in the following error:
Error:osgi: [security.thread] Exception: java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:406)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at aQute.bnd.osgi.Builder.build(Builder.java:116)
at org.jetbrains.osgi.jps.build.BndWrapper.doBuild(BndWrapper.java:262)
at org.jetbrains.osgi.jps.build.BndWrapper.build(BndWrapper.java:192)
at org.jetbrains.osgi.jps.build.OsgiBuildSession.doBuild(OsgiBuildSession.java:211)
at org.jetbrains.osgi.jps.build.OsgiBuildSession.build(OsgiBuildSession.java:79)
at org.jetbrains.osgi.jps.build.OsmorcBuilder.build(OsmorcBuilder.java:54)
at org.jetbrains.osgi.jps.build.OsmorcBuilder.build(OsmorcBuilder.java:33)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildTarget(IncProjectBuilder.java:1023)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1004)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1065)
at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:956)
at org.jetbrains.jps.incremental.IncProjectBuilder.access$500(IncProjectBuilder.java:73)
at org.jetbrains.jps.incremental.IncProjectBuilder$BuildParallelizer.lambda$queueTask$0(IncProjectBuilder.java:927)

RCP: JxBrowser license check failed: No valid license found

Today I started experimenting with JxBrowser. Starting the sample with the public static main worked as expected (and it could find the license.jar).
I added a button to a view to start the sample:
btnStart.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
new JxBrowserJavaFXSWT();
}
});
Now I'm receiving:
Caused by: java.lang.RuntimeException: JxBrowser license check failed: No valid license found.
Which is actually odd because it's added the classpath. I tried adding a new Plugin-Project (which is loaded fine) and add the license.jar to its classpath: not working.
I tried to add it to the manifest.mf, build.properties
manifest.mf
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: License
Bundle-SymbolicName: com.teamdev.jxbrowser.license
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.teamdev.jxbrowser.license.Activator
Bundle-Vendor: TEAMDEV
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
build.properties
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
license.jar
src.includes = license.jar
jars.extra.classpath = license.jar
Question: is there a way to add the license.jar to my rcp project and/or what am I missing?
P.S.: if informations are missing to help me solve this I'll gladly add more code, etc
I received the same error, and I have a solution.
Just create a new mail ID and send a request to get a license of JX Browser using that new account, and get it and Download.
Then add that license.jar file in your project. It worked.
You probably need the license.jar in the main plugin class path - the 'Bundle-Classpath'.
Open the MANIFEST.MF editor, switch to the Runtime tab and add the license.jar to the Classpath section (you should also still have the . entry). The Bundle-Classpath should end up looking like:
Bundle-ClassPath: .,
library.jar
I can't give you a perfect answer but I can give you a hint.
First you can extract the licence.jar file to change the extension from .jar to .zip.
Then you can see the following file:
Product: JxBrowser
Version: 6.x
Licensed to:
License type: Evaluation
License info: Single-user license
Expiration date: 22-03-2099
Support expiration date: 22-03-2099
Generation date: 20-02-2017
Platforms: mac/x64;win32/x64;linux/x64;mac/x86;linux/x86;win32/x86;mac/ppc
Company name: NO COMPANY
SigB: jpg317l89241ihodylpum17e2gnk1ufx7bsql1dboldc25pp941s7ksw0wph
SigA: mdluetwphf1vcbl2yzs3ks5c4417pexopgnmap146g8ggk4r4e9ucrzmf1xo
You have to change the values of SigB and SigA.
I tried it, after changing date, but it does not work.

Osgi java.lang.NoClassDefFoundError when trying to retrieve a service from another bundle

So, let's see, I have three bundles: Provider interface, Provider implementation and Client.
Everything is running smoothly on Eclipse, but when I export the bundles and run em, the following error appears when I try to retrieve the Provider Service:
java.lang.NoClassDefFoundError: provider/providerinterface/ProviderService
The interface is exporting his package, so there should be no errors with that. Alongside, Client is also importing the providerInterface package in its manifest.
The .jar of the Provider interface bundle does have the ProviderService class inside, so there are no error exporting either.
Provider Interface's manifest:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: IMA_Provider
Bundle-SymbolicName: IMA_Provider
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: provider.providerinterface
Client's manifest:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MAClient
Bundle-SymbolicName: MA_Client
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: provider.providerinterface,
org.osgi.framework;version="1.3.0",
org.osgi.util.tracker;version="1.4.2"
Provider and Client are just symbolic names, the "Client" bundle imports and uses a lot of other classes from many other bundles with no errors whatsoever. Anyway, I'm getting stuck with this one, and I can't find any reason.
Any help?
Usually there is something wrong with the build.properties file, causing the bundles to miss the actual class files. This does not matter when running directly from Eclipse, but it does matter when you export the bundles using PDE.
Things to check:
Are the classfiles really in the bundles? When checking the bundle, you should have at least at toplevel a provider/ folder and a META-INF/ folder
the build.properties file should look something like:
output.. = bin/
source.. = src/
bin.includes = META-INF/,.
Good luck, Frank
I was finally able to solve this.
There were no issues with the Manifest files or the build.properties, this was a constructor problem.
The MA_Provider implementation was lacking a void constructor; Once I added this
public ProviderImpl(){}
on the implementation class of the ProviderInterface, the OSGi bundles were able to retrieve the service.

Eclipse Plugin Fragment

Does anyone have a "hello world" sample or tutorial for creating an Eclipse plugin fragment?
I have a working host plugin that, for the sake of simplicity, is just this...
public void start(BundleContext context) throws Exception {
System.out.println("Hello....");
super.start(context);
plugin = this;
}
public void stop(BundleContext context) throws Exception {
System.out.println("Goodbye...");
plugin = null;
super.stop(context);
}
Simple enough and works. Now I want to add a fragment to that host, which seems not as simple as creating a plugin host. I just don't see how to create a fragment project and add logic to it. Let's say I just want to do something simple and have the fragment to print a "Hello2" at start() and "Goodbye2" at stop(). Can someone give me a working example?
Eclipse -> File -> New... -> Fragment project -> set the host plugin (which is either in your workspace or in plugins in target platform).
Open Plugin manifest editor (you can do it by clicking on build.properties, manifest.mf or fragment.xml - if there is no such a file, create it by hand)
In tab Extentions click Add.. and add org.eclipse.ui.startup and browse class which implements org.eclipse.ui.IStartup class.
Create this class and implement it. You need to implement method earlyStartup() which is entry point to the fragment.
Note: The lines below are just example. I didn't test it so there might be errors...
All you need is this (this is project structure / directory structure):
Fragment-Project - root dir
/META-INF
MANIFEST.MF
/src (which is source directory)
FragmentStartClass.java (which implement org.eclipse.ui.IStartup interface and earlyStartup method)
build.properties
fragment.xml
META-INF/MANIFEST.MF content:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: FragmentProject
Bundle-SymbolicName: FragmentProject;singleton:=true
Bundle-Version: 1.0.0
Bundle-ClassPath: src/,.
Fragment-Host: *HostPluginProjectSymbolicName*;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle:
build.properties content:
source.. = src,\
output.. = bin/
bin.includes = META-INF/,
.,
fragment.xml
fragment.xml content:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<fragment>
<extension
point="org.eclipse.ui.startup">
<startup
class="FragmentStartClass">
</startup>
</extension>
</fragment>
FragmentStartClass.java content:
import org.eclipse.ui.IStartup;
public class FragmentStartClass implements IStartup {
public void earlyStartup() {
System.out.println("Hello World From Fragment!");
}
}
Well, first off what are you trying to accomplish? Are you sure fragments are the solution?
Fragments are simply additions to an existing plugin. There is no Bundle-Activator to "startup" the fragment. You just gain the additional resources in the fragment. You could use an extension point to inform the host that some particular functionality was extended by a present fragment. Think of it as merging the two at runtime.
See this note from the Eclipse Wiki.
I'm not sure if you can do this without the host plugin knowing something about loading the fragment's extra implementation code.
For example:
MyInterface o = null;
try {
Class<?> c = getClass().getClassLoader().loadClass("my.fragment.Activator");
o = (MyInterface) c.newInstance();
} catch (ClassNotFoundException e) {
}
if (o != null) {
o.start();
}
where MyInterface is an interface defined in the host plugin, and implemented by your fragment.
Another way might be to have the fragment provide an extension point identifying the extended class, but that is probably more than is needed.
I think what you are trying to do is better served by using extension points and separate plugins, as you want to add functionality to the base plugin.
Fragments are only used to add resources or extra classes to the base plugin.
For the record, I just created an Eclipse Fragment that contains some PMD Java Rule classes.
Next to the class files, there is only one file required in that Jar: META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.acme.tools.pmd
Bundle-SymbolicName: com.acme.tools.pmd;singleton:=true
Bundle-Version: 1.0.0
Fragment-Host: net.sourceforge.pmd.eclipse.plugin;bundle-version="3.2.6"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
I tried this with current Eclipse 3.7. Deployment is by placing the Jar file into <eclipse root>/dropins/plugins (create that folder if it's not yet there).

Categories