Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

Hi, it's my understanding that if I want to use a JAR library from within my "Java in the Database" code, I need to include the directory which contains the JAR to my CLASSPATH environment variable. However, this doesn't seem to be working and I get NoClassDefFound errors.

I also tried extracting the JAR and setting the CLASSPATH to the root folder of the extracted JAR files, but still no luck.

It seems to work if I import every single class from the JAR into the database, but I would really prefer avoiding adding 2000+ classes to the database.

Shouldn't the CLASSPATH be used to resolve any missing class dependencies? What am I doing wrong?

Thanks!

asked 12 Dec '12, 09:39

glitch003's gravatar image

glitch003
31336
accept rate: 0%


You should not be putting the JAR in the classpath. Instead you should be installing the JAR right into the database. Please have a look at the INSTALL JAVA JAR statement.

permanent link

answered 12 Dec '12, 10:33

Karim%20Khamis's gravatar image

Karim Khamis
5.7k53870
accept rate: 40%

Hi, when I try to install the JAR I get errors that classes are already present and the import fails. I can clearly see in Sybase Central > External Environments > Java > Classes that no classes are already present. So importing the JAR fails, and I had to import each class manually into the database.

It seems like you're telling me that Java in the Database can only see other classes that have been imported. Is that the case?

The documentation seems to imply that classes in the CLASSPATH can be used:

The Sun Java Runtime Environment and the Sun JDK Java compiler use the CLASSPATH environment variable to locate classes referenced within Java code. A CLASSPATH variable provides the link between Java code and the actual file path or URL location of the classes being referenced. For example, import java.io.* allows all the classes in the java.io package to be referenced without a fully qualified name. Only the class name is required in the following Java code to use classes from the java.io package. The CLASSPATH environment variable on the system where the Java class declaration is to be compiled must include the location of the Java directory, the root of the java.io package.

(12 Dec '12, 10:48) glitch003

When you import a class using the IMPORT JAVA statement do you also get an error?

(12 Dec '12, 21:03) Derli Marcochi
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×438
×78

question asked: 12 Dec '12, 09:39

question was seen: 2,069 times

last updated: 12 Dec '12, 21:03