I include an external .jar, but I'm asked to import its libs
I succeed to include ojdbc14_g.jar to my project, but I am asked to import OracleConnectionPoolDataSource which is included in ojdbc14_g.jar.
Here is my code:
<path id="myclasspath">
<fileset dir="lib/">
<include nam开发者_开发技巧e="*.jar"/>
</fileset>
</path>
<pathconvert property="lib.project.manifest.classpath" pathsep=" ">
<path refid="myclasspath"/>
<flattenmapper/>
</pathconvert>
<target name="compile" description="compile" depends="init">
<javac srcdir="${sources}" destdir="${classes}" >
<classpath refid="myclasspath"/>
</javac>
</target>
<target name="packaging" description=" jar construction" depends="compile" >
<echo message="construction" />
<jar destfile="${dist}/Integration.jar" basedir="${classes}">
<fileset dir=".">
<include name="lib/ojdbc14_g.jar" />
</fileset>
<manifest>
<attribute name="Main-Class" value="packRMI.ServerRMI" />
<attribute name="Class-Path" value="${lib.project.manifest.classpath}"/>
</manifest>
</jar>
</target>
<target name="run" description="execution" depends="packaging">
<java jar="${dist}/Integration.jar" fork="true"/>
</target>
But when it runs, it gives me this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/pool/OracleConnectionPoolDataSource
Because the following import can't be done:
import oracle.jdbc.pool.OracleConnectionPoolDataSource;
How can I resolve this?
It looks like your problem is that you're including the ojdbc14_g.jar file directly in your application jar file. The java classloader can't find classes in jar files nested like this.
If you want to produce a single final jar, then instead of adding ojdbc14_g.jar itself to your jar, you can try adding its contents to your jar.
In your build file, where you are creating your jar, change this:
<fileset dir=".">
<include name="lib/ojdbc14_g.jar" />
</fileset>
to this:
<zipfileset src="lib/ojdbc14_g.jar" />
You may need to look out for conflicts between the contents of ojdbc_g.jar and your files, in particular the manifest, I'm not sure how ant will handle them.
Alternatively, you could leave the ojdbc jar separate from your application jar, and reference it using the Class-Path attribute of your manifest (you appear to already be doing this for some other libs).
精彩评论