NoClassDefFoundError exception while using external library in EMF plugin project - java

I'm working on a EMF project where I've created a ecore model from a mdl file. I created the corresponding gencore file and generated the code from the gencore file. While EMF has a own serialization mechanism based on XMI I want to support my project with a own serializiation mechanism.
So far, I've done the necessary steps and if I use the debugger the corresponding methods are called. In order to read and write a file representation of my model I want to use an external library. I've done the following steps
Created a directory lib/ in my plugin project where I've put the external library
Added the library to the build path of the project
Added the directory to the bundle-classpath (Manifest.mf)
Added the directory to the bin.includes of the build.properties
If I try to run my code I get a NoClassDefFoundError exception and I don't know why. I've created a run configuration where I'm starting the project as a eclipse application. So somebody has an idea what I'm missing?
Thanks in advance!
Michael
Edit: Below my Manifest.mf file
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: de.hs_rm.cs.vs.dsm.OWL
Bundle-SymbolicName: de.hs_rm.cs.vs.dsm.owl;singleton:=true
Bundle-Version: 1.0.0
Bundle-ClassPath: lib/,
.
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: owl,
owl.impl,
owl.util,
rdfs,
rdfs.impl,
rdfs.util
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport
Bundle-ActivationPolicy: lazy
and also my build.properties
bin.includes = .,\
model/,\
META-INF/,\
plugin.xml,\
plugin.properties,\
lib/
jars.compile.order = lib/,\
.
source.. = src/
output.. = bin/
source.lib/ = lib/
jars.extra.classpath = lib/owlapi-bin.jar

it's not really a hundred percent solution since I'm not aware what exactly the problem was at all. I've found a link where somebody had the exactly same problem (added a jar as library, NoClassDefFoundError exception during execution). So far, the necessary steps are:
Import JARs using the "Import -> File System"
Add the JAR-file(s) to the classpath section of the Manifest/plugin.xml runtime tab
Press "New..." to add "." library back to the classpath
Check that the binary build exports the new JAR-file(s) on the Build tab
Press save
Select the coressponding project in the project explorer view, right click and select "PDE Tools -> Update classpath". This will add the newly added JAR-file(s) to the project's classpath.
I've had some trouble with the last step since I've added the library by myself to the build path of the project. Every time I did this eclipse removed the library from the build path while executing the "Update classpath command". I've repeated step six without adding the library to the build path by myself and it's now working.
It seems a bit odd to me, but it's now working. Anyway I would like to thank you for your help!
Regards,
Michael

If you are writing Eclipse plugins and not plain old Java project you must add your library in the classpath field of the Runtime tab of the Manifest.mf editor.

Do you get the NoClassDefFoundError when trying to access the lib or when trying to access the Ecore model? If it is the latter case, check, whether your emf package has been registered in the plugin.xml file. Look for something like the following part:
<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="«package URI here»"
class="«package class name here»"
genModel="«genmodel location here»"/>
</extension>
This part can be missing, if the plugin.xml was generated before the genmodel was used for generation, as neither the manifest, nor the plugin.xml gets updated during the code generation process.
On the other hand, if the library accessing throws the exception, then I would try to remove and re-add the dependency, or clean build a project, but these seem unlikely to solve the exception.

Related

Change how Gradle's build directory is organized

So, I've recently (partially) completed a Java project with Gradle. Importantly, the project uses absolute pathing to access files in my resources folder, since those files will change after the JAR is made. When I use Eclipse's "export as runnable JAR" functionality, I get something that works perfectly - putting the .jar file in my main directory lets it find everything. However, using Gradle's build function doesn't, because Gradle adds extra layers between the .jar and the resources. To demonstrate, here's my "normal" directory:
./program root directory
|_program.jar
|_resources
|_[actual resources]
And here's the directory Gradle makes:
./build folder
|_libs
| |_program.jar
|_resources
|_main
|_[actual resources]
What I want from Gradle is:
./build folder
|_program.jar
|_resources
|_[actual resources]
Yes, I could manually move the resources and program.jar around in the directory to achieve this, but that feels wrong - this is exactly what Gradle is supposed to do for me, right? I know there has to be SOME way to do it. I just don't know how. So that's why I'm asking for help - how do I do this?
To change the output of resources:
sourceSets.main.output.resourcesDir = "$buildDir/resources"
To change where the JAR file is put:
jar {
// use destinationDir for Gradle < 5.1
destinationDirectory = buildDir
}
If all your resources are meant to be external you may want to exclude them from the JAR file:
jar {
include '**/*.class'
destinationDirectory = buildDir
}
That will only include .class files from the jar task's input. You can customize this using the include and exclude options.

GWT How to Modify default project sample code?

When we create a new GWT project using the Eclipse plugin, it gives an option to generate sample source code for the project as shown below:
Selecting the above option, generates sample code structure that looks something like this:
MyTestProject
src/
com/
mytestproject/
MyTestProject.gwt.xml
client/
GreetingService.java
GreetingServiceAsync.java
MyTestProject.java
server/
GreetingServiceImpl.java war/
MyTestProject.css
MyTestProject.html
WEB-INF/
web.xml
classes/
lib/
...GWT JARs...
I wanted to know if there is a way to modify/customize this default code to automatically generate a few more classes to jump start my projects. Any suggestions to get me started in the right direction will be appreciated. For example how do I find the source from where this code is getting generated or more popular approach to create such templates for kick-starting a new project.
You can create your own sample/template project with as many classes as you need, add it to a git/mercurial repository, and import from this repository every time you start a new project.

The class folder is not associated to any output library entry

My Eclipse plugin project which holds libraries used by other OSGi plugins gives me the following warning:
The class folder 'lib/' is not associated to any output library entry.
What does it mean? Can I safely ignore it?
The whole feature consisting from 20 plugins works well, but I do not like to have any warnings in my code.
My build.properties file is:
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
bin/,\
lib/,\
.
The search on google gave me this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=297483, but I'm still not sure how to fix this warning.
I found this hint to be helpfull (first google hit, as of 03-SEP-2013)
http://dev.eclipse.org/mhonarc/lists/pde-dev/msg01822.html
I removed META-INF from my bundle build path, cleaned (rebuilt) the project and the warning disappeared.
About the build.properties:
META-INF/ should be included in the bin.includes because actually this folder includes all the information associated to the classpath and runtime information. If not, another warning appears.
Icons must be added as well in the bin.includes.
Actually, we should try to avoid the addition of icons in the runtime information:
Statically declared plug-in icons are not meant to be in the runtime JAR >because Eclipse wants to load plug-ins lazily. In other words, during >loading of the platform, the platform loader reads only the plugin.xml >file and will use the icons that are declared there.
Taken from: https://wiki.eclipse.org/FAQ_Can_I_add_icons_declared_by_my_plugin.xml_in_the_runtime_JAR%3F
Example of one of my plugins:
Figure 1. Adding information in the bin.includes property
The reason is simple. Think about we want to deploy our plugin somewhere else. Then, we need to maintain a track about all the information that needs our plugin to be executed.
About the MANIFEST.MF:
There is another trick to organize the information that appears in the MANIFEST.MF besides the information that appears in the build.properties:
PDE provides an Organize Manifests wizard to help ensure that the >information in your Manifest is up to date. The wizard is available >through the Plug-in Tools menu after right clicking on a plug-in project's MANIFEST.MF or plugin.xml files.
Taken from: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fguide%2Ftools%2Fpde_actions%2Forganize_manifests.htm
Example of one of my plugins:
Figure 2. Organizing MANIFEST.MF
I think your issue is that in your MANIFEST.MF the section Bundle-ClassPath does not include a listing of the libraries. This means OSGi will not know if these classes are meant to be on the internal classpath. You will have to provide that information.
If you export everything in lib, every single one has to be listed in the MANIFEST.MF and the wildcard lib/ is fine for the PDE builder.
If you only want some in lib/ then you need to list those only, and the builder will either need an explicit list, or an exclude clause for the ones that you do not want.
If you are just using the libraries internally, but do not want to export them, then the settings for the exported packages are used.
I am unsure what to do in the case where you are packing up a jar file but actually do not want it on the classpath. I am guessing that a source.exclude with the name of the library might help. This is a really unusual corner case.
Bundle-ClassPath: lib/amf-aml_2.12-4.1.19.jar,
lib/amf-core_2.12-4.1.20.jar,
lib/amf-validation_2.12-4.0.3.jar,
lib/amf-webapi_2.12-4.0.3.jar,
lib/antlr4-runtime-4.5.3.jar,
lib/collection-0.7.jar,
lib/commons-beanutils-1.9.3.jar,
lib/commons-cli-1.4.jar,
lib/commons-codec-1.11.jar,
lib/commons-collections-3.2.2.jar,
lib/commons-compress-1.19.jar,
lib/commons-csv-1.5.jar,
lib/commons-digester-1.8.1.jar,
lib/commons-io-2.6.jar,
lib/commons-lang3-3.4.jar,
lib/commons-logging-1.2.jar,
lib/commons-validator-1.6.jar,
lib/handy-uri-templates-2.1.6.jar,
lib/httpclient-4.5.5.jar,
lib/httpclient-cache-4.5.5.jar,
lib/httpcore-4.4.9.jar,
lib/jackson-annotations-2.9.0.jar,
lib/jackson-core-2.9.8.jar,
lib/jackson-databind-2.9.8.jar,
lib/jcl-over-slf4j-1.7.26.jar,
lib/jena-arq-3.11.0.jar,
lib/jena-base-3.11.0.jar,
lib/jena-core-3.11.0.jar,
lib/jena-iri-3.11.0.jar,
lib/jena-shaded-guava-3.11.0.jar,
lib/joda-time-2.9.4.jar,
lib/json-20180130.jar,
lib/json4s-ast_2.12-3.5.4.jar,
lib/json4s-core_2.12-3.5.4.jar,
lib/json4s-native_2.12-3.5.4.jar,
lib/json4s-scalap_2.12-3.5.4.jar,
lib/jsonld-java-0.12.3.jar,
lib/libthrift-0.12.0.jar,
lib/org.everit.json.schema-1.9.2.jar,
lib/paranamer-2.8.jar,
lib/re2j-1.1.jar,
lib/scala-common_2.12-0.5.64.jar,
lib/scalactic_2.12-3.0.5.jar,
lib/scala-java8-compat_2.12-0.8.0.jar,
lib/scalajs-stubs_2.12-0.6.29.jar,
lib/scala-library-2.12.6.jar,
lib/scala-reflect-2.12.8.jar,
lib/scalatest_2.12-3.0.5.jar,
lib/scala-xml_2.12-1.0.6.jar,
lib/scopt_2.12-3.7.0.jar,
lib/shacl-1.3.0.jar,
lib/slf4j-api-1.7.26.jar,
lib/slf4j-simple-1.7.12.jar,
lib/syaml_2.12-0.7.270.jar,
lib/webapi-parser-0.5.0.jar,
lib/webapi-parser-0.5.0-javadoc.jar,
lib/webapi-parser-0.5.0-sources.jar,
.

Could not instantiate the Payment module

I added a new language in KonaKart app and I've added all necessary property files.
I activated the modules: shipping and payment.
For standard languages the modules work fine, but for my added languages I get the following exception:
Can't find bundle for base name com.konakart.bl.modules.payment.paypal.Paypal lacale ru
at java.util.ResourceBundle.throwMissingResourceException
in the folder /com/konakart/bl/modules/payment/paypal I've added the file Paypal_ru.properties
I think I need to add a property file to the classpath.
How do I add the property file to the classpath?
With KonaKart you get the full source code for the modules and an ANT build file to rebuild the jars. Hence the easiest way to do this is to add the properties file for your new locale in the appropriate directory for your module and rebuild the jar.

Use Bundle-NativeCode on Linux does not work

I create a plugin which includes the following folder structure:
src
native/so/libsystemcommand.so
META-INF/MANIFEST.MF
The manifest include the command
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Commands Plug-in
Bundle-SymbolicName: de.system.commands;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: de.system.commands.CommandsPlugin
Bundle-Localization: plugin
Bundle-NativeCode: native/so/libsystemcommand.so; osname = Linux; processor = x86
Require-Bundle: org.eclipse.core.runtime,
org.apache.commons.logging
Eclipse-AutoStart: true
Export-Package: de.system.commands,
de.system.commands.jni,
de.system.commands.utils
Bundle-ClassPath: .
The build.properties looks like
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
native/
In the start method of my Activator class I call
System.loadLibrary("systemcommand");
At runtime the library is not found and a UnsatisfiedLinkError is thrown.
java.lang.UnsatisfiedLinkError: no libsystemcommand in java.library.path
Do I have to set more attributes in the plugin? Do I have to unzip some informations on the target platform?
EDIT:
java.library.path=/opt/jdk/j2re1.4.2_16/lib/i386/client:/opt/jdk/j2re1.4.2_16/lib/i386:/opt/jdk/j2re1.4.2_16/../lib/i386::/opt/dsa/lib:/opt/dsa/lib
I wonder if the library needs to be specified without the lib prefix? E.g.,
System.loadLibrary("systemcommand");
Since that is how the library would be passed on a gcc link line.
The lib has to be in your filesystem (not in an archive file).
Then you can either use the linux environment variable LD_LIBRARY_PATH pointing to the lib or define the property java.library.path
In a plugin fragment for linux, I use:
Bundle-NativeCode: librptlc.so; osname = linux; processor=x86
And in the main plugin I use:
if (OS.equals(Platform.OS_LINUX)) {
System.loadLibrary("rptlc");
}
This should work within one plugin too.
I seem to remember having some problems with libraries in a sub folder in the jar, but I'm not sure why this would be the case. I just stuck to having the libraries in the root of a plugin fragment instead, which works for me.
You could also try getting the file system path of the library (not sure if that's easy) and loading it using:
libraryPath = "C:\eclipse\bundles\123\librptlc.so";
System.load(libraryPath);
I think i found the solution.
We only build the plugin which was not working and copy it to the destination platform directory. After this we start the application as wtach the log files whether the library was foud or not.
What we miss, was to delete the configurations folder. The new plugin was not unzipp and the library was not existing in the configurations directory.
Im sorry and thank you for your answers.
EDIT :
The configuration folder is placed at
<installation>/eclipse/configuration/
At least delete everything without the file
<installation>/eclipse/configuration/config.ini

Categories

Resources