设置使用QueryDSL和MySQL数据库的maven插件

时间:2011-03-01 15:43:05

标签: java mysql maven maven-plugin querydsl

我正在尝试设置我的项目,以便我可以对MySQL数据库使用querydsl-sql。 我想获取类并使用maven生成类,并且在设置插件时遇到问题。

我尝试从可用的示例here

配置pom.xml
<plugin>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-maven-plugin</artifactId>
    <version>2.1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>export</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>
        <jdbcUrl>jdbc:mysql:mydb:3306/alltrades</jdbcUrl>
        <jdbcUser>mvaz</jdbcUser>
        <packageName>com.three60t.tools.bonus.persistence</packageName>
        <targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
    </dependencies>
</plugin>

pom中也给出了对mysql-connector-java的依赖。 我得到的问题是它似乎找不到驱动程序:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building tools-bonus
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] [querydsl:export {execution: default}]
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[ERROR] 
java.sql.SQLException: No suitable driver found for jdbc:mysql:mydb:3306/alltrades
        at java.sql.DriverManager.getConnection(DriverManager.java:602)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at com.mysema.query.maven.AbstractMetaDataExportMojo.execute(AbstractMetaDataExportMojo.java:134)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] No suitable driver found for jdbc:mysql:mydb:3306/alltrades

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue Mar 01 16:34:47 CET 2011
[INFO] Final Memory: 23M/219M
[INFO] ------------------------------------------------------------------------

有人可以帮我吗? 如何指定驱动程序?

2 个答案:

答案 0 :(得分:2)

您的依赖项似乎是正确的,但您的JDBC URL看起来很时髦。试试<jdbcUrl>jdbc:mysql://localhost:3306/alltrades</jdbcUrl>MySQL Reference Manual声明如下:

  

MySQL Connector / J的JDBC URL格式如下,方括号([,])中的项是可选的:

     

jdbc:mysql:// [host] [,failoverhost ...] [:port] / [database]»   [= propertyValue1] [&安培; propertyName2] [propertyName1?] [= propertyValue2] ...

     

如果未指定主机名,则默认为127.0.0.1。如果未指定端口,则默认为3306,即MySQL服务器的默认端口号。

您可能还需要指定jdbcPassword。有关其他选项,请查看Querydsl Reference Manual

答案 1 :(得分:1)

正确指定了驱动程序,如果驱动程序出错,则会出现不同的异常:

Class.forName(jdbcDriver); 
Connection conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);

这也是孤立失败的吗?它看起来像是jdbcUrl格式的错误。