Java Reference
In-Depth Information
java -cp ibatis-sqlmap-2.jar:ibatis-common-2.jar:. MyMainClass
If you are using i BATIS in an application server, consult the documentation that
comes with the server for the appropriate way to add i BATIS to the classpath for
your application.
Using iBATIS with a web application
When setting up a web application, you should put the i BATIS JAR files in the web
application's WEB-INF/lib directory.
It may be tempting to put the i BATIS jars into a shared location. For
example, with Tomcat, those would be the shared/lib or common/lib
directories. However, putting JAR s like this in a shared location is gener-
ally a bad idea unless it is required for some reason (like a JDBC driver
that is being used by a JNDI data source).
One reason that putting jar files in a shared location is a bad idea is
that upgrading becomes riskier. For example, in an environment where
you have 10 applications sharing a JAR file, if you need to upgrade the
JAR for one application, you have to test it for all 10 that use it. In addi-
tion, there are classloader issues to consider. The exact same bytecode
loaded by two different classloaders are considered by Java to be different
classes. This means that static variables are not shared, and if you try to
cast one to the other, you will get a ClassCastException , even though
the classes are identical. Another classloader issue that you would likely
encounter is the matter of how the classloader finds resources. For exam-
ple, if the common/lib classloader in Tomcat loads i BATIS , it cannot see a
configuration file in a web application using that classloader.
To sum it up: if you put your i BATIS JAR anywhere but in the WEB-INF/lib direc-
tory of your web application and it does not work, do not bother posting a ques-
tion to the mailing lists. The first thing you will be told is to move it to the WEB-
INF/lib directory.
3.5 i BATIS and JDBC
A deep definition of JDBC is beyond the scope of this topic, but we will cover it
from a high level to provide a foundation for the rest of the topic.
Sun's JDBC API is the standard for database connectivity for the Java program-
ming language. JDBC is one part of the Java technology that allows you to realize
the “write once, run anywhere” promise, because all database interaction uses
JDBC to access data.
Search WWH ::

Custom Search