我在JBoss Fuse服務器中創建了一個簡單的Apache Camel應用程序。 我的駱駝藍圖無法讀取驅動程序類。無法加載JDBC驅動程序類
這是錯誤消息:
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver'
...
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver from bundle 144 (fer-cdr)
...
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver not found by jdbccamel
...
這是項目結構:
+-- Root
+== pom.xml
+-- jdbccamel (Maven Module)
| +-- pom.xml
| +-- /src/main/resources/OSGI-INF/blueprint/blueprint.xml
+-- features (Maven Modul => contains fabric feature of the project)
| +-- pom.xml
| +-- scr/main/resources/features.xml
的pom.xml(jdbccamel)
....
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>${camel.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${version.maven-bundle-plugin}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Include-Resource>{maven-resources}</Include-Resource>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
....
p om.xml(功能)
....
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>target/features/features.xml</file>
<type>xml</type>
<classifier>features</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
....
features.xml(功能)
....
<?xml version="1.0" encoding="UTF-8"?>
<features name="myfeature" xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
<repository>mvn:org.apache.karaf.assemblies.features/standard/2.3.0.redhat-60024/xml/features</repository>
<repository>mvn:org.apache.karaf.assemblies.features/enterprise/2.3.0.redhat-60024/xml/features</repository>
<repository>mvn:org.apache.cxf.karaf/apache-cxf/2.7.10/xml/features</repository>
<repository>mvn:org.apache.camel.karaf/apache-camel/2.12.3/xml/features</repository>
<repository>mvn:org.apache.activemq/activemq-karaf/5.8.0.redhat-60024/xml/features</repository>
<feature name="fer-cdr">
<bundle>wrap:mvn:com.oracle/ojdbc6/11.2.0.3</bundle>
<bundle>wrap:mvn:mysql/mysql-connector-java/5.1.6</bundle>
<bundle>wrap:mvn:commons-dbcp/commons-dbcp/1.4</bundle>
<bundle>wrap:mvn:commons-pool/commons-pool/1.4</bundle>
<feature version="2.12.3">camel-core</feature>
<feature version="2.12.3">camel-blueprint</feature>
<feature version="2.12.3">camel-jdbc</feature>
<feature version="(3.1,4.0]">spring-jdbc</feature>
<bundle>mvn:com.project/jdbccamel/1.5.9</bundle>
</feature>
</features>
....
blueprint.xml(jdbccamel)
....
<bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource">
<property name="driverClassName" value="oracle.jdbc.driver" />
<property name="url" value="${cdr.url}" />
<property name="username" value="${cdr.username}" />
<property name="password" value="${cdr.password}" />
<property name="initialSize" value="${cdr.initialSize}" />
<property name="maxActive" value="${cdr.maxActive}" />
<property name="testOnBorrow" value="${cdr.testOnBorrow}" />
<property name="validationQuery" value="${cdr.validationQuery}" />
</bean>
....
我的發現: 當我maven-bundle-plugin中的import-package(請參閱jdbccamel中的pom.xml)
<Import-Package>oracle.jdbc.driver</Import-Package>
這樣的:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${version.maven-bundle-plugin}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Include-Resource>{maven-resources}</Include-Resource>
</instructions>
</configuration>
</plugin>
的org.apache.commons.dbcp.BasicDataSource類將不加載和我得到的消息是這樣的:
org.osgi.service.resolver.ResolutionException: Unable to resolve dummy/0.0.0: missing requirement [dummy/0.0.0] osgi.identity; osgi.identity=jdbccamel; type=karaf.feature; version=0 [caused by: Unable to resolve jdbccamel/0.0.0: missing requirement [jdbccamel/0.0.0] osgi.identity; osgi.identity=jdbccamel; type=osgi.bundle; version="[1.5.9,1.5.9]" [caused by: Unable to resolve jdbccamel/1.5.9: missing requirement [jdbccamel/1.5.9] osgi.wiring.package; filter:="(osgi.wiring.package=org.apache.commons.dbcp.BasicDataSource)"]]
at org.apache.felix.resolver.Candidates.populateResource(Candidates.java:285)
at org.apache.felix.resolver.Candidates.populate(Candidates.java:153)
at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:148)
at io.fabric8.agent.DeploymentBuilder.resolve(DeploymentBuilder.java:231)
at io.fabric8.agent.DeploymentAgent.doUpdate(DeploymentAgent.java:567)
at io.fabric8.agent.DeploymentAgent$2.run(DeploymentAgent.java:293)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
當我添加兩個,像這樣:
<Import-Package>oracle.jdbc.driver,org.apache.commons.dbcp.BasicDataSource</Import-Package>
它無法加載JDBC驅動程序l之前。
[求助]問題是設置驅動程序類'oracle.jdbc.driver'而不是'oracle.jdbc.driver'。OracleDriver' – smftr