我试图通过调用ANT脚本从maven调用org.h2.tools.RunScript类。
maven看起来像......
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo>Starting DB</echo>
<ant antfile="${basedir}/dbbuild.xml" target="dbdo" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
ant脚本看起来像这样:
<project name="" default="make" basedir=".">
<target name="make">
<property value="." name="basedir" />
<java classname="org.h2.tools.RunScript"
fork="true"
maxmemory="128m" >
<arg line="-user " />
<arg value=" sa" />
<arg line="-driver "/>
<arg value="org.h2.Driver" />
<arg line="-url " />
<arg value=" "jdbc:h2:file:${basedir}\\mydb;LOCK_MODE=3""/>
<arg line="-script " />
<arg value=" ${basedir}/src/main/resources/database/h2/testSchema.sql"/>
<classpath>
<pathelement path="${runtime_classpath}"/>
</classpath>
</java>
</target>
</project>
我一直收到这个错误:
[java] Exception in thread "main" java.sql.SQLException: No suitable driver
found for jdbc:h2:file:C:\Apps\development\workspace\Phase3_1\directpay\quickpay
\\mydb;LOCK_MODE=3
[java] at java.sql.DriverManager.getConnection(DriverManager.java:602)
[java] at java.sql.DriverManager.getConnection(DriverManager.java:185)
[java] at org.h2.tools.RunScript.process(RunScript.java:312)
[java] at org.h2.tools.RunScript.runTool(RunScript.java:140)
[java] at org.h2.tools.RunScript.main(RunScript.java:68)
[java] Java Result: 1
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------
h2-1.3.163.jar位于类路径中。任何帮助将不胜感激 感谢
答案 0 :(得分:0)
我发现了这个问题。 RunScript的文档调用url参数周围的引号... [-help]或[ - ?]打印选项列表 [-url&#34;&lt; url&gt;&#34;]数据库网址(jdbc:...)
我逃脱了;在参数的两边,一旦我删除了引号,它就可以正常工作。我把arg设置为:
<arg line="-url" />
<arg value="jdbc:h2:${basedir}\mydb;LOCK_MODE=3;TRACE_LEVEL_FILE=3"/>