cancel
Showing results for 
Search instead for 
Did you mean: 

Referencing JARs for Java in the Database

Former Member
0 Kudos
2,431

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!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

0 Kudos

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