Я пробовал небольшой проект maven, и я пытаюсь подключиться к базе данных db2, поэтому мне нужен com.ibm.db2.jcc.DB2Driver
jar для соединения.
Я пробовал много методов из Интернета, но все еще не получилось, вот некоторыеметода, который я попробовал:
изменить в pom.xml
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.5.0.7</version>
<scope>system</scope>
<systemPath>
/home/Workspace/book/springData/lib/db2jcc4-10.5.0.7.jar
</systemPath>
</dependency>
использовать команду maven для установки:
mvn install:install-file -Dfile=/home/Workspace/book/springData/lib/db2jcc4-10.5.0.7.jar -DpomFile=/home/Workspace/book/springData/pom.xml
или
mvn install:install-file -Dfile=/home/meow/Workspace/mbsb-cib/springData/lib/db2jcc4-10.5.0.7.jar -DgroupId=com.ibm.db2 -DartifactId=db2jcc4 -Dversion=10.5.0.7 -Dpackaging=jar -DgeneratePom=true
Но я все еще не могу загрузить драйвер JDBC.
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.ibm.db2.jcc.DB2Driver]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 70 more
Caused by: java.lang.IllegalStateException: Could not load JDBC driver class [com.ibm.db2.jcc.DB2Driver]
at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:150)
at com.journaldev.spring.config.DataConfig.dataSource(DataConfig.java:52)
at com.journaldev.spring.config.DataConfig$$EnhancerBySpringCGLIB$$46013fb.CGLIB$dataSource$0(<generated>)
at com.journaldev.spring.config.DataConfig$$EnhancerBySpringCGLIB$$46013fb$$FastClassBySpringCGLIB$$8fec3ead.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at com.journaldev.spring.config.DataConfig$$EnhancerBySpringCGLIB$$46013fb.dataSource(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 71 more
Caused by: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver from [Module "deployment.springData.war" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:147)
... 82 more