0

I already install JCo3 for linux.

I'm using ubuntu 16.04 x86_64 and java-8-oracle

As the documentation said, I need to add LD_LIBRARY_PATH and CLASSPATH to JCo directory.

export LD_LIBRARY_PATH=/home/zain/sapjco
export CLASSPATH=/home/zain/sapjco/sapjco3.jar

then create simple JCo connection test, but when I run my project I got error

error: package com.sap.conn.jco does not exist

Is there any particular step I missed?

Code:

import com.sap.conn.jco.*;
public class testjco {
     public static void main(String[] args) {
          JCO.Client mConnection;
          try {
                    mConnection = JCO.createClient("301", // SAP client
                                                         "somecoolguy", // userid
                                                          "****", // password
                                                          "EN", // language
                                                          "XXX", // application server host name
                                                          "00"); // system number
               mConnection.connect();
               System.out.println(mConnection.getAttributes());
               mConnection.disconnect();
          } catch (Exception ex) {
               ex.printStackTrace();
               System.exit(1);
          }
     }
}
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
zain
  • 3
  • 7
  • Is that the entire error message? Which steps did you perform to compile and run your application, what messages did you get? – vwegert Sep 15 '16 at 05:17

2 Answers2

0

I don't know if you've already done this but:

export LD_LIBRARY_PATH=/home/zain/sapjco
export CLASSPATH=/home/zain/sapjco/sapjco3.jar

only work in the current bash instance, which means that if you ever close that terminal window then that export path will be gone. One way to keep it is to add it to your ~/.profile

then you can just run this source ~/.bashrc in order to refresh your bash window.

Don't know if that helped since I have never coded Java in Ubuntu, only on Mac with Eclipse/Idea. Anyways, if that's not how to do it, then there's a problem with the way you imported your sapjco3.jar to your project.

Pandawan
  • 117
  • 3
  • 11
0

You also need to use your CLASSPATH environment variable and pass it as classpath argument to your JVM instance that shall run your project.

But I don't think that you are really at the step of running your project, you must be already failing to compile your class testjco. (By the way, I recommend to follow the common Java naming conventions and let all class names start with an uppercase letter.)

You are importing the package com.sap.conn.jco which belongs to the SAP Java Connector 3.0 (sapjco3.jar), but in your code you use the JCo API from package com.sap.mw.jco of the outdated SAP Java Connector 2.0/2.1 (sapjco.jar). That does not work and cannot be compiled.

Trixx
  • 1,796
  • 1
  • 15
  • 18