English 中文(简体)
Setup of maven plugin for using QueryDSL with a MySQL database
原标题:

I m trying to setup my project so that I can use querydsl-sql against a MySQL database. I d like to get the classes and generate the classes using maven and am having problems setting up the plugin.

I ve tried configuring the pom.xml from the example available here

<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>

The dependency to mysql-connector-java is also given in the pom. The problem that I m getting is that it doesn t seem to find the driver:

[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] ------------------------------------------------------------------------

Can someone help me with this? How can I specify the driver?

最佳回答

Your dependencies seem to be correct, but your JDBC URL looks funky. Try <jdbcUrl>jdbc:mysql://localhost:3306/alltrades</jdbcUrl>. The MySQL Reference Manual states the following:

The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:

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

If the host name is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers.

You also might need to specify a jdbcPassword. For other options look at the Querydsl Reference Manual.

问题回答

The driver is specified correctly, if the driver would be wrong you would get a different Exception :

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

Does this also fail in isolation? It looks like an error in the jdbcUrl format.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签