05-13-2010 4:33 PM
Hi, i've created a standalone app that sends data to R/3 via java jco connector, all's fine when using eclipse but when i create a JAR to be able to install in several machines, the jar does not run it throws an exception
C:\teste>java -jar deamon.jar jcoToR3.tester
2010-05-13 16:09:31
Exception in thread "main" java.lang.NoClassDefFoundError: com/sap/conn/jco/ext/
DestinationDataProvider
at jcoToR3.tester.main(tester.java:37)
Caused by: java.lang.ClassNotFoundException: com.sap.conn.jco.ext.DestinationDat
aProvider
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
any idea?
thzs in advance to all
Jaime
05-13-2010 11:15 PM
HI,
You need to pass in the fullpath of your classes using CLASSPATH, I usually use a .BAT file to do so.
Example:
java -classpath <fullpath of 1.jar>;<fullpath of 2.jar> <java executable>
Thanks,
Arash
05-13-2010 11:15 PM
HI,
You need to pass in the fullpath of your classes using CLASSPATH, I usually use a .BAT file to do so.
Example:
java -classpath <fullpath of 1.jar>;<fullpath of 2.jar> <java executable>
Thanks,
Arash
05-14-2010 9:18 AM
Hi Arash,
But when using -jar the classpath is not available, the spjco3.jar in inside the deamon.jar.
I'll try it and give some feedback
thankzs
Jaime
05-14-2010 4:00 PM
Hi,
it's running by java -classpath but not with the JAR file.
And i've added in the MANIFEST
Class-Path: lib/sapjco3.jar
Any idea my?
Regards
Jaime
05-17-2010 7:48 AM
Hello friend,
Actually I am doing JCO development in my laptop recently and it works correctly, please refer to my enviroment settings, hope it help you.
CLASSPATH: D:\JAVA Tool\sapjco3-NTintel-3.0.4\sapjco3.jar
when I compile the class, I would like to write a .bat to compile them in CMD.
javac -nowarn -classpath ..\..\externallib\_comp\libraries\bcmail-jdk14-141.jar;..\..\externallib\_comp\libraries\bcprov-jdk14-141.jar;..\..\externallib\_comp\libraries\CFCACertKitJS.jar;..\..\externallib\_comp\libraries\jitCipher.jar;..\..\externallib\_comp\libraries\JITTSAAPI.jar;..\..\externallib\_comp\libraries\log4j-1.2.8.jar;..\..\externallib\_comp\libraries\PKIBASE.jar;..\..\externallib\_comp\libraries\sapjco3.jar .\source\com\sap\*.java
pause
when I execute the compiled class I also would like to use a .bat to run class:
%JAVA_HOME%\bin\java -classpath ./source;..\..\externallib\_comp\libraries\bcmail-jdk14-141.jar;..\..\externallib\_comp\libraries\bcprov-jdk14-141.jar;..\..\externallib\_comp\libraries\CFCACertKitJS.jar;..\..\externallib\_comp\libraries\jitCipher.jar;..\..\externallib\_comp\libraries\JITTSAAPI.jar;..\..\externallib\_comp\libraries\log4j-1.2.8.jar;..\..\externallib\_comp\libraries\PKIBASE.jar;..\..\externallib\_comp\libraries\sapjco3.jar com.sap.CFCAServer
you can see how to configure the path of sapjco3.jar in PATH and CLASSPATH in above bat file.
05-17-2010 10:22 AM
Hi Jerry,
First of all thanks for the tip.
I'm able to run the compiled class my trouble is to run the program by the jar file. My scenario is as follows:
- The stand alone app runs fine on eclipse
- The stand alone app runs fine on CMD, running with java -classpath <sapjco3.jar>; <myClass.class>;
- I create a jar with my app and the sapjco3.jar and try t run the jar with java -jar <myClass.jar>; and get and class not found error, it does not´st recognize the classpath on the MANIFEST file of the jar
any idea?
Regards
Jaime
05-17-2010 12:01 PM
If I understand you correct, you have packaged the sapjco3.jar inside another jar file. If that's correct, then this shouldn't work, because the default system class loader does not handle jar files inside jar files.
The [Class-Path|http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html] header in the manifest only references other jars that are not inside the given jar:
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.
Essentially you have three options (I'd go for the first one, because then you can upgrade your JCo library independent of your application):<ol><li>Simply ship the sapjco3.jar along with your jar and reference it in the manifest of your jar (but don't package it inside your jar)</li>
<li>Unpack the sapjco3.jar and create one big jar that contains all the data (Choose export to Runnable JAR file instead of JAR file and you'll see the additional options for including classes from libraries)</li>
<li>Search for a class loader that handles jar-in-jar files and utilize it instead of the default system class loader</li>
</ol>
The last two options have the advantage that you can ship a single JAR file, which is often what people want...
Cheers, harald
05-17-2010 2:19 PM
Hi Harald,
your correct but if tried to point to a jar file outside the jar and it didin't work
MANIFEST filfe
Manifest-Version: 1.0
Class-Path: C:\teste\lib\sapjco3.jar;C:\Users\Jaime Cordeiro\workspace\automatoToSap\bin;C:\teste\jtds-1.2.5.jar
Main-Class: jcoToR3.tester
and to run
java -jar deamon1.jar jcoToR3.tester
is the class-path wrong?
But with the runnable jar it works fine many thanks for the help.
I'd like to thanks to all for the help.
Regards
Jaime
05-18-2010 1:57 AM
is the class-path wrong?
As you probably already guessed by the failure of your test, the answer is yes, the class path is wrong...
The problem is that java basically expects URL's in the Class-Path attribute; furthermore, different directories or jar files are separated by spaces, not by semicolons. So to make your example work, you could either choose to use relative paths or if you want to stick to absolute paths use something like this (for demo purpose I shortened your example as we'd otherwise end up with an endless line):
Class-Path: file:///C:/lib/sapjco3.jar file:///C:/Users/Jaime%20Cordeiro/workspace
Note that I had to escape/encode the space character in your second directory Jaime Cordeiro (as otherwise this would not be recognized as one single URL).
If you want it a bit shorter, you can omit the file:// header, though you still have to indicate with a leading slash '/' that you start at the root of the file system:
Class-Path: /C:/lib/sapjco3.jar /C:/Users/Jaime%20Cordeiro/workspace
Cheers, harald
05-18-2010 10:32 AM
Hi Harald,
once again many thanks for the help. I'll try to change the class-path and run it again but the sugestion of exec jar works fine for my needs.
Regards
Jaime