为什么maven编译时不需要sqljdbc4 maven的驱动包

1、目的:我在开发环境中想引用相对路径的数据库驱动jar包,以便在部署环境不必修改数据库驱动的位置。(用maven管理jar包,而不用在开发环境一个配置,部署环境也有另一个配置)2、问题:不知道怎么引用相对路径的jar包?3、这是pom.xml中mybatis-generator-maven-plugin插件的配置
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748&&plugin& &
& & & & &&!--
& & & & &用maven mybatis插件
& & & & &如果不在plugin里面添加依赖包得引用的话,会找不到相关得jar包,
& & & & &在plugin外部得jar包,他不会去找到并执行,
& & & & &所以要把plugin运行依赖得jar配置都放在里面
& & & & & --&
& & & & &groupId&org.mybatis.generator&/groupId& &
& & & & &artifactId&mybatis-generator-maven-plugin&/artifactId& &
& & & & &version&1.3.2&/version& &
& & & & &executions& &
& & & & & & &execution& &
& & & & & & & & &id&Generate MyBatis Artifacts&/id& &
& & & & & & & & &goals& &
& & & & & & & & & & &goal&generate&/goal& &
& & & & & & & & &/goals& &
& & & & & & &/execution& &
& & & & &/executions& &
& & & & &configuration& &
& & & & & & &verbose&true&/verbose& &
& & & & & & &overwrite&true&/overwrite& &
& & & & & &
& & & & & & &jdbcDriver&com.mysql.jdbc.Driver&/jdbcDriver&
& & & & & & &jdbcURL&jdbc:mysql://115.24.32.213:3306/test&/jdbcURL&
& & & & & & &jdbcUserId&root&/jdbcUserId&
& & & & & & &jdbcPassword&****&/jdbcPassword& &
& & & & & &
& & & & &/configuration& &
& & & & &dependencies& &
& & & & & & &dependency& &
& & & & & & & & &groupId&mysql&/groupId& &
& & & & & & & & &artifactId&mysql-connector-java&/artifactId& &
& & & & & & & & &&!-- 引用依赖库的版本 --&
& & & & & & & & &version&5.1.35&/version& &
& & & & & & &/dependency& &
& & & & & & &dependency& &
& & & & & & & & &groupId&org.mybatis.generator&/groupId& &
& & & & & & & & &artifactId&mybatis-generator-core&/artifactId& &
& & & & & & & & &version&1.3.2&/version& &
& & & & & & &/dependency& &
& & & & & & &dependency& &
& & & & & & & & &groupId&org.mybatis&/groupId& &
& & & & & & & & &artifactId&mybatis&/artifactId& &
& & & & & & & & &!-- 引用依赖库的版本 --&
& & & & & & & & &version&${mybatis.version}&/version& &
& & & & & & &/dependency& &
& & & & &/dependencies& &
4、这是generatorConfig.xml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768&?xml version=&1.0& encoding=&UTF-8& ?& &
&!DOCTYPE generatorConfiguration PUBLIC &-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN& &http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd& & &
&generatorConfiguration& &
& & &!-- 引入配置文件 --& &
& & &properties resource=&jdbc.properties&/& &
& & &!-- 一个数据库一个context --& &
& & &context id=&infoGuardian&& &
& & & & &!-- 注释 --& &
& & & & &commentGenerator & &
& & & & & & &property name=&suppressAllComments& value=&false&/&&!-- 是否取消注释 --& &
& & & & & & &property name=&suppressDate& value=&true& /& &!-- 是否生成注释代时间戳--& &
& & & & &/commentGenerator& &
& & & & &!-- jdbc连接 --& &
& & & & &jdbcConnection driverClass=&${driver}& &
& & & & & & connectionURL=&${url}& userId=&${user}& &
& & & & & & password=&${password}& /& &
& & & & &!-- 类型转换 --& &
& & & & &javaTypeResolver& &
& & & & & & &!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) --& &
& & & & & & &property name=&forceBigDecimals& value=&false&/& &
& & & & &/javaTypeResolver& &
& & & & &!-- 生成实体类地址 --& & &
& & & & &javaModelGenerator targetPackage=&org.luojj.model& &
& & & & & & targetProject=&src& & &
& & & & & & &!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --& &
& & & & & & &property name=&enableSubPackages& value=&false&/& &
& & & & & & &!-- 是否针对string类型的字段在set的时候进行trim调用 --& &
& & & & & & &property name=&trimStrings& value=&true&/& &
& & & & &/javaModelGenerator& &
& & & & &!-- 生成mapxml文件 --& &
& & & & &sqlMapGenerator targetPackage=&org.luojj.mapping& &
& & & & & & targetProject=&src& & &
& & & & & & &!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --& &
& & & & & & &property name=&enableSubPackages& value=&false& /& &
& & & & &/sqlMapGenerator& &
& & & & &!-- 生成mapxml对应client,也就是接口dao --& & & &
& & & & &javaClientGenerator targetPackage=&org.luojj.dao& &
& & & & & & targetProject=&src& type=&XMLMAPPER& & &
& & & & & & &!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --& &
& & & & & & &property name=&enableSubPackages& value=&false& /& &
& & & & &/javaClientGenerator& &
& & & & &!-- 配置表信息 --& & & &
& & & & &table &tableName=&students& &
& & & & & & domainObjectName=&Student& enableCountByExample=&false& &
& & & & & & enableDeleteByExample=&false& enableSelectByExample=&false& &
& & & & & & enableUpdateByExample=&false&& &
& & & & & & &!-- &tableName为对应的数据库表 domainObjectName是要生成的实体类名 enable*ByExample &
& & & & & & & & 是否生成 example类 & --& &
& & & & & & &
& & & & & & &!-- 忽略列,不生成bean 字段 --& &
& & & & & & &ignoreColumn column=&FRED& /& &
& & & & & & &!-- 指定列的java数据类型 --& &
& & & & & & &!--
& & & & & & &columnOverride column=&LONG_VARCHAR_FIELD& jdbcType=&VARCHAR& /&
& & & & & & &--&
& & & & &/table& &
& & &/context& &
&/generatorConfiguration&
5、这是错误提示
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (Generate MyBatis Artifacts) on project test333: Execution Generate MyBatis Artifacts of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.Driver -& [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (Generate MyBatis Artifacts) on project test333: Execution Generate MyBatis Artifacts of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed: Exception getting JDBC Driver
& & at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
& & at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
& & at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
& & at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
& & at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
& & at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
& & at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
& & at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
& & at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
& & at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
& & at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
& & at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
& & at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
& & at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
& & at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
& & at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
& & at java.lang.reflect.Method.invoke(Method.java:606)
& & at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
& & at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
& & at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
& & at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
& & at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution Generate MyBatis Artifacts of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed: Exception getting JDBC Driver
& & at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
& & at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
& & ... 21 more
Caused by: java.lang.RuntimeException: Exception getting JDBC Driver
& & at org.mybatis.generator.internal.db.ConnectionFactory.getDriver(ConnectionFactory.java:85)
& & at org.mybatis.generator.internal.db.ConnectionFactory.getConnection(ConnectionFactory.java:54)
& & at org.mybatis.generator.config.Context.getConnection(Context.java:526)
& & at org.mybatis.generator.config.Context.introspectTables(Context.java:436)
& & at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:222)
& & at org.mybatis.generator.maven.MyBatisGeneratorMojo.execute(MyBatisGeneratorMojo.java:203)
& & at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
& & ... 22 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver &
& & at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
& & at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
& & at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
& & at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
& & at java.lang.Class.forName0(Native Method)
& & at java.lang.Class.forName(Class.java:270)
& & at org.mybatis.generator.internal.ObjectFactory.internalClassForName(ObjectFactory.java:150)
& & at org.mybatis.generator.internal.ObjectFactory.externalClassForName(ObjectFactory.java:121)
& & at org.mybatis.generator.internal.db.ConnectionFactory.getDriver(ConnectionFactory.java:82)
& & ... 28 more
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
自己找到问题。jdbc.propertis的
1driver=com.mysql.jdbc.Driver
的后面多一个空格
本文出自操他妈,转载时请注明出处及相应链接。
本文永久链接: http://www.caotama.com/57953.html
Ɣ回顶部trackbacks-0
之前 , 不使用 maven 管理 jar 包的时候 , 链接 SQL Server 数据库的时候用的都是 sqljdbc4.jar 驱动包 , 刚用 maven 做测试的时候 , 到中央仓库找不到 sqljdbc4.jar 的坐标 , 到网上搜了一下 , 说是可以用&jtds 通过 jdbc 来链接 SQL Server , 实验了一下 , 果真行 !pom.xml :
&&&& ... ... ... ... ...&&& &!--&sql&server&driver&--&&&&&&dependency&&&&&&&&groupId&net.sourceforge.jtds&/groupId&&&&&&&&artifactId&jtds&/artifactId&&&&&&&&version&<span style="color: #.2.4&/version&&&&&&/dependency&&&& ... ... ... ... ...hibernate.cfg.xml :
&hibernate-configuration&&&&&&session-factory&&&&&&&&&&!--&Database&connection&settings&--&&&&&&&&&&property&name="connection.driver_class"&net.sourceforge.jtds.jdbc.Driver&/property&&&&&&&&&&property&name="connection.url"&jdbc:jtds:sqlserver://localhost:1433/TEST&/property&&&&&&&&&&property&name="connection.username"&USERNAME&/property&&&&&&&&&&property&name="connection.password"&PASSWORD&/property&&&&&&&&&&!--&JDBC&connection&pool&(use&the&built-in)&&&&&&&&&&property&name="connection.pool_size"&1&/property&&&&&&&&&--&&&&&&&&&&&&&&&&&&!--&SQL&dialect&--&&&&&&&&&&property&name="dialect"&org.hibernate.dialect.HSQLDialect&/property&&&&&&&&&&!--&Enable&Hibernate's&automatic&session&context&management&&&&&&&&&&property&name="current_session_context_class"&thread&/property&&&&&&&&&--&&&&&&&&&&&&&&&&&&!--&Disable&the&second-level&cache&&&&&&&&&&&property&name="cache.provider_class"&org.hibernate.cache.NoCacheProvider&/property&&&&&&&&&--&&&&&&&&&&!--&Echo&all&executed&SQL&to&stdout&--&&&&&&&&&&property&name="show_sql"&true&/property&&&&&&&&&&&&&&&&&&!--&&&&&&&&&&&property&name="format_sql"&true&/property&&&&&&&&&--&&&&&&&&&&&&&&&&&&!--&Drop&and&re-create&the&database&schema&on&startup&&&&&&&&&&property&name="hbm2ddl.auto"&update&/property&&&&&&&&&--&&&&&&&&&&!--&&&&&&&&&&&mapping&resource="com/fancy/po/person.hbm.xml"/&&&&&&&&&--&&&&&&&&&&&&&&/session-factory&&/hibernate-configuration&&&
阅读(9536)
随笔分类(8)
随笔档案(104)
积分与排名
阅读排行榜1、找到可用的oracle jdbs驱动jar包文件,放置到指定目录(可根据实际自定义) D:\jdbc\ojdbc14.jar &
2、安装好maven,主要是配置好环境变量 MAVEN_HOME='指向maven的安装目录'
3、打开cmd窗口,跳转至D:\jdbc目录,执行命令
& &&mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackaging=jar -Dfile=ojdbc14.jar
  注:-Dversion 可根据时间的版本更改, -Dfile 需要对应实际放入jdbc目录下的jar文件
& 如果一切正常,mvn指令提示成功,你可以去本地的maven库路径找到:com\oracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar
4、在需要引入的maven工程的pom.xml内增加引入即可
&dependency&& &&groupId&com.oracle&/groupId&& &&artifactId&ojdbc14&/artifactId&& &&version&10.2.0.1.0&/version&
&/dependency&
阅读(...) 评论()maven为什么could not load com.mysql.jdbc.driver_百度知道
maven为什么could not load com.mysql.jdbc.driver
我有更好的答案
&&&mysql&/groupId&&&&&&&&&&artifactId&mysql-connector-java&/artifactId&gt&&&dependency&&&&&&&&&&groupId&&&&version&5.1.15-bin&/version&&&&&&/dependency&&&&nbsp
采纳率:71%
为您推荐:
其他类似问题
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。&nbsp>&nbsp
&nbsp>&nbsp
java教程 &nbsp>&nbsp
maven官方库中没有oracle jdbc驱动的问题解决
摘要:1、找到可用的oraclejdbs驱动jar包文件,放置到指定目录(可根据实际自定义)D:/jdbc/ojdbc14.jar&2、安装好maven,主要是配置好环境变量MAVEN_HOME='指向maven的安装目录'3、打开cmd窗口,跳转至D:/jdbc目录,执行命令&&&mvninstall:install-file-DgroupId=com.oracle-DartifactId=ojdbc14-Dversion=10.2.0.1
1、找到可用的oracle jdbs驱动jar包文件,放置到指定目录(可根据实际自定义) D:/jdbc/ojdbc14.jar &
2、安装好maven,主要是配置好环境变量 MAVEN_HOME='指向maven的安装目录'
3、打开cmd窗口,跳转至D:/jdbc目录,执行命令
& &&mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackaging=jar -Dfile=ojdbc14.jar
注:-Dversion 可根据时间的版本更改, -Dfile 需要对应实际放入jdbc目录下的jar文件
& 如果一切正常,mvn指令提示成功,你可以去本地的maven库路径找到:com/oracle/ojdbc14/10.2.0.1.0/ojdbc14-10.2.0.1.0.jar
4、在需要引入的maven工程的pom.xml内增加引入即可
&dependency&& &&groupId&com.oracle&/groupId&& &&artifactId&ojdbc14&/artifactId&& &&version&10.2.0.1.0&/version& &/dependency&
以上是的内容,更多
的内容,请您使用右上方搜索功能获取相关信息。
若你要投稿、删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内给你回复。
云服务器 ECS
可弹性伸缩、安全稳定、简单易用
&40.8元/月起
预测未发生的攻击
&24元/月起
为您提供0门槛上云实践机会
你可能还喜欢
你可能感兴趣
阿里云教程中心为您免费提供
maven官方库中没有oracle jdbc驱动的问题解决相关信息,包括
的信息,所有maven官方库中没有oracle jdbc驱动的问题解决相关内容均不代表阿里云的意见!投稿删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内答复
售前咨询热线
服务与支持
账号与支持
关注阿里云
International

我要回帖

更多关于 sqljdbc4 maven 的文章

 

随机推荐