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
Related
I'm trying to execute jar file of netbeans swing small project.
The file isn't executing.
I need to make it work by double clicking on the jar file that is located in:
C:\Users\armyTik\Documents\NetBeansProjects\Notepad\dist\Notepad.jar
extra details:
properties -> Build -> Packaging -> "Build JAR after compiling" and "Copy Dependent Libraries" are checked.
properties -> run -> Main class: "notepad.NotepadComponent"
In the cmd, by manually executing the jar file I get the following error:
cd C:\Users\armyTik\Documents\NetBeansProjects\Notepad\dist
java -jar Notepad.jar
"Error: Could not find or load main class notepad.Notepad"
What should I do, specifically?
EDIT:
I extracted the jar file and got:
META-INF/MANIFEST.MF
notepad/FileManager.class
notepad/icon.gif
notepad/NotepadComponent$1.class
notepad/NotepadComponent$2.class
notepad/NotepadComponent$3.class
notepad/NotepadComponent$4.class
notepad/NotepadComponent$5.class
notepad/NotepadComponent$6.class
notepad/NotepadComponent$7.class
notepad/NotepadComponent.class
notepad/Thumbs.db
META-INF/MANIFEST.MF content:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_102-b14 (Oracle Corporation)
Class-Path:
X-COMMENT: Main-Class will be added automatically by build
Main-Class: notepad.NotepadComponent
Update2:
I got new exception while trying to open the jar from the cmd:
While opening the project from netbeans, the icon is shown with no exception.
*****When I remove the icons , The jar is working! but I need to keep the icons in the application.
This is because your classpath is not correct.
Try it like this:
java -cp "<PATH>/Notepad.jar" notepad.Notepad
If this does not work then unpack the jar file and confirm the package and class name is correct, Print CLASSPATH env variable or check java and javac versions.
I've been struggling with this common error and just can't resolve it. This application is composed of multiple packages and runs fine within JCreator (at the moment I need to use this IDE rather than Eclipse).
My manifest file is here (there are 2 blank lines at the end):
Manifest-Version: 1.0
Created-By: 1.6.0_45 (Sun Microsystems Inc.)
Main-Class: C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\main\DPMain
I wrote a bat file to create the jar:
jar -cvfm DPlus.jar C:\COMPILE\MyProjects\douwe\classes\MANIFEST.MF
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\main*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\library*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\command*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file\display*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\command*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file\display*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\gui*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\gui*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\job*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\job*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\types*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\util*.class
When I try to execute with the command
C:\COMPILE\MyProjects\douwe\classes>java -jar DPlus.jar
I always get the error:
Error: Could not find or load main class C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\main\DPMain
Can anyone see what I'm doing wrong here?
Usually this error is due to MANIFEST.MF if the'res no application's entry point has been set.
Your manifest file should have this line of code
Main-Class: YourPackage.DPMain
Alternatively, you can do the following.
java -cp .;app.jar YourPackage.DPMain
In my implementation, there are something different from yours, you can refer:
(1) The folder(before compressed) structure
you need to add a META-INF folder and put your MANIFEST.MF in it
(2) The content in your MANIFEST.MF
I think your should use the package format instead of a folder tree format:
Manifest-Version: 1.0
Main-Class: com.loadtest.mgr.LoadTestStarter
I have a jar whose content looks as shown below,
Below is my manifest file
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.7.0_06-b24 (Oracle Corporation)
Main-Class: org.sai.com.DerbyDemo
Class-Path: derby.jar derbyclient.jar derbynet.jar derbytools.jar
When i try to run the jar, it has thrown a ClassNotFoundExcception meaning it isn't referencing the jars inside the outer jar.
In the Class-Path attribute, how can I reference jars (derby.jar, etc) inside the actual jar?
You will need a custom class loader for this, have a look at One Jar.
One-JAR lets you package a Java application together with its dependency Jars into a single executable Jar file.
It has an ant task which can simplify the building of it as well.
REFERENCE (from background)
Most developers reasonably assume that putting a dependency Jar file into their own Jar file, and adding a Class-Path attribute to the META-INF/MANIFEST will do the trick:
jarname.jar
| /META-INF
| | MANIFEST.MF
| | Main-Class: com.mydomain.mypackage.Main
| | Class-Path: commons-logging.jar
| /com/mydomain/mypackage
| | Main.class
| commons-logging.jar
Unfortunately this is does not work. The Java Launcher$AppClassLoader does not know how to load classes from a Jar inside a Jar with this kind of Class-Path. Trying to use jar:file:jarname.jar!/commons-logging.jar also leads down a dead-end. This approach will only work if you install (i.e. scatter) the supporting Jar files into the directory where the jarname.jar file is installed.
You can't. From the official tutorial:
By using the Class-Path header in the manifest, you can avoid having
to specify a long -classpath flag when invoking Java to run the your
application.
Note: The Class-Path header points to classes or JAR files on the
local network, not JAR files within the JAR file or classes accessible
over internet protocols. To load classes in JAR files within a JAR
file into the class path, you must write custom code to load those
classes. For example, if MyJar.jar contains another JAR file called
MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's
manifest to load classes in MyUtils.jar into the class path.
In Eclipse you have option to export executable jar.
You have an option to package all project related jars into generated jar and in this way eclipse add custom class loader which will refer to you integrated jars within new jar.
Default implementations of the classloader cannot load from a jar-within-a-jar: in order to do so, the entire 'sub-jar' would have to be loaded into memory, which defeats the random-access benefits of the jar format (reference pending - I'll make an edit once I find the documentation supporting this).
I recommend using a program such as JarSplice to bundle everything for you into one clean executable jar.
Edit: Couldn't find the source reference, but here's an un-resolved RFE off the Sun website describing this exact 'problem': http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648386
Also, you could 'test' that your program works by placing the library jar files in a \lib sub-directory of your classes directory, then running from the command line. In other words, with the following directory structure:
classes/org/sai/com/DerbyDemo.class
classes/org/sai/com/OtherClassFiles.class
classes/lib/derby.jar
classes/lib/derbyclient.jar
From the command line, navigate to the above-mentioned 'classes' directory, and type:
java -cp .:lib/* org.sai.com.DerbyDemo
if you do not want to create a custom class loader. You can read the jar file stream. And transfer it to a File object. Then you can get the url of the File. Send it to the URLClassLoader, you can load the jar file as you want.
sample:
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("example"+ ".jar");
final File tempFile = File.createTempFile("temp", ".jar");
tempFile.deleteOnExit(); // you can delete the temp file or not
try (FileOutputStream out = new FileOutputStream(tempFile)) {
IOUtils.copy(resourceAsStream, out);
}
IOUtils.closeQuietly(resourceAsStream);
URL url = tempFile.toURI().toURL();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{url});
urlClassLoader.loadClass()
...
Add the jar files to your library(if using netbeans) and modify your manifest's file classpath as follows:
Class-Path: lib/derby.jar lib/derbyclient.jar lib/derbynet.jar lib/derbytools.jar
a similar answer exists here
in eclipse, right click project, select RunAs -> Run Configuration and save your run configuration, this will be used when you next export as Runnable JARs
I am struggling to get my Java program to run on AIX. I used Eclipse on Windows to create a runnable Jar file, jRams.jar below. I kept on getting a class not found error, until finally I put all the external libraries in the same directory.
$ ls
JAXB2_20081030.jar
JAXB2_20110601.jar
activation.jar
asjava.jar
commons-beanutils-1.8.3.jar
commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-core-1.8.3.jar
commons-codec-1.5.jar
commons-collections-3.2.1.jar
commons-configuration-1.6.jar
commons-digester-2.1.jar
commons-jxpath-1.3.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
commons-logging-adapters-1.1.1.jar
commons-logging-api-1.1.1.jar
jRams.jar
jaxb-api.jar
jaxb-impl.jar
jaxb-xjc.jar
jaxb1-impl.jar
jremote.jar
jsr173_1.0_api.jar
log4j-1.2.16.jar
netty-3.2.4.Final.jar
$
Still, I get the class not found error.
$ java -jar jRams.jar
The java class is not found: com.jbase.jremote.JRemoteException
jremote.jar definitely contains JRemoteException. Why isn't this working?
UPDATE
Thank you for your straight-to-the-point answers. I now understand the nature of a java application and a manifest file far better.
Turns out my ftp client was transferring in ASCII mode and not Binary, so the jar files were corrupt. I have learned a great deal, nonetheless.
When using the -jar option, you need to specify which jar-files should be on your class path in the manifest file. Just having the required jar files in the same directory won't do it.
Add a line in your manifest that says:
Class-Path: JAXB2_20081030.jar:JAXB2_20110601.jar:....:netty-3.2.4.Final.jar
or skip the -jar option and launch using
java -cp JAXB2_20081030.jar:....:netty-3.2.4.Final.jar:jRams.jar pkg.JRamsMain
and it should work fine.
(Note that on *nix systems, as opposed to Windows machines, the jar files in the class paths should be separated using : instead of ;.)
Further reading:
The Java Tutorials: Adding Classes to the JAR File's Classpath
You need to add all those JARs to the runtime CLASSPATH by adding the -classpath parameter. AIX requires you to separate the JARs using :
You will have to specify the full path(if libraries not in the same directory as jRams) or just the names of the jar file in a manifest file (If all dependency jars are in the same folder). Alternative specify the path to all the dependent jars using -cp argument.
Example (This assume every dependency is in the same directory you are executing java command from):
java -cp commons-collections-3.2.1.jar; jaxb-impl.jar; etc.. ;jRams.jar package_to_class.MyMainClass.java
Where package_to_class is example: com.myproj.example.
EDITED.
Follow these steps to add "Class-Path" to existing jar file -
Create "newmanifest" file with following entry
Class-Path: additional/jars
Update existing jar file e.g. "classes.jar"
jar --update --manifest=newmanifest --file classes.jar
Inflate jar file
jar -xvf classes.jar
created: META-INF/
inflated: META-INF/MANIFEST.MF
Verify "Class-Path" is added to MANIFEST.MF
cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
main-class: CLASSNAME
Created-By: 15.0.2 (Oracle Corporation)
Class-Path: additional/jars
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.