cancel
Showing results for 
Search instead for 
Did you mean: 

Error JCo starting .jar file

rolf_winter2
Explorer
0 Kudos

Dear all,

I am new to Java, but I try to implement a small application which talks to our SAP. I am working with eclipse 3.3 and I've installed JCO 2.1.8. I modified Example1 a little bit and everything works fine when I start my program within eclipse with run as->java application. I added the sapjco.jar file to the build path of my project. I also added C:\Programme\sapjco-ntintel-2.1.8 to my windows path variable and copied *.dll to system32. When I export my project as a .jar file and try to start it with

java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. -jar Jco.jar

I get the error message

java.lang.NoClassDefFoundError: com/sap/mw/jco/IMetaData

The contents of my .classpath file is:

<?xml version="1.0" encoding="UTF-8"?>

<classpath>

<classpathentry kind="src" path="src"/>

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

<classpathentry kind="lib" path="C:/Programme/sapjco-ntintel-2.1.8/sapjco.jar"/>

<classpathentry kind="output" path="bin"/>

</classpath>

But I can start the java program with

java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. Jco

when I am in the directory with the .class file.

Whats wrong with my .jar file?

Thanks in advance,

Rolf

Message was edited by:

Rolf Winter

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

u can try with setting the path of the sapjco.jar in the <b> PATH Environment variables </b>.

Please do reward with points if the problem is solved.

Thanks

ritu

rolf_winter2
Explorer
0 Kudos

Hi,

thanks for your answers.

C:\Programme\sapjco-ntintel-2.1.8 containing sapjco.jar is already added to the path environment variable.

summary:

-I installed JCO in folder C:\Programme\sapjco-ntintel-2.1.8

-I copied *.dll to Windows\system32

-I added C:\Programme\sapjco-ntintel-2.1.8 to the path environment variable

-sapjco.jar is in the building path

-<i>I can start the "normal Java .class file"</i> with java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. Jco

-I've created a jar file with the export dialog. I just followed the steps and selected the starting class "Jco".

-In the directory containing the jar file I tried to start it with the following commands

java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;. -jar Jco.jar

java -jar Jco.jar

but I always get the message

Exception in thread "main" java.lang.NoClassDefFoundError: com/sap/mw/jco/IMetaData

Any further ideas?

Rolf

Former Member
0 Kudos

Rolf,

Did you try out the option I gave you in the previous response. i.e. exporting from NWDS. It works...

Regards,

Prem

rolf_winter2
Explorer
0 Kudos

Hi Prem,

I'm currently developing in "native" eclipse so I can't use this option.

Regards,

Rolf

rolf_winter2
Explorer
0 Kudos

Not a solution, but a workaround:

there is a plugin for eclipse called fat jar. http://fjep.sourceforge.net

This pluging creates a jar file that includes also the referenced libraries. After creating the fat jar you can simply execute it by java -jar xyz.jar

Another workaround is creating the jar file using the export dialog. After that I created a subdirectory "lib" and copied the sapjco.jar in it. Then I opened the jar archive using winzip and edited the manifest.mf file. I simply added one line:

Class-Path: lib/sapjco.jar

The disadvantage is that you always have to move the lib directory with the jar file.

Still waiting for the "real" solution.

former_member182294
Active Contributor
0 Kudos

Hi Rolf,

If you want to make your Jar file as executable you should supply all the dependent jars in the same archieve and mention them in the manifiest file. Reason is if you are making Jar executable it should be able to run in any environment so you should supply all required jars.

But for your problem here is the direct solution, add your Jco.jar to cp and give the main class name.

java -cp C:\Programme\sapjco-ntintel-2.1.8\sapjco.jar;.;Jco.jar <b>YourMainClass</b>

Regards

Abhilash

rolf_winter2
Explorer
0 Kudos

Thanks Abhilash,

now it works

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Rolf,

Welcome to SDN!!

If you want to make a jar file out of your project, you can do so in NWDS itself.

Right click on your project structure when you are in the Resource/java Perspective, select Export -> JAR File -> (leave all the selections untouched, but select the destination jar file here which in your case is Test.jar) . Follow the rest of the steps and you will generate your jar file.

I guess this should do. Kindly check it up and get back if u have any difficulty.

If this answer helped you consider rewarding points

regards,

Prem.