3
votes

I am trying to write an Ant (1.8.2) script to shutdown HSQLDB (2.1.0) from the command line - basically I need to be able to shutdown HSQLDB from a Windows batch file - after searching the web it seems like there is no built-in command line way to do it - please correct me if I am wrong.

I've started the database up with the shipped batch file runServer.bat.

Here is my ant file (shutdown.xml):

<project>

<target name="hsqldb-stop">
  <sql
    classpath="C:\programs\hsqldb\hsqldb-2.1.0\hsqldb\lib"
    driver="org.hsqldb.jdbcDriver"
    url="jdbc:hsqldb:hsql://localhost:9001"
    userid="sa" password=""
    autocommit="true">SHUTDOWN</sql>
</target>

</project>

classpath is where I have the C:\programs\hsqldb\hsqldb-2.1.0\hsqldb\lib\hsqldb.jar file. All the other details are those that I use when I access the database from Java, and they do work there.

When I run it I get:

>ant -buildfile shutdown.xml
Buildfile: shutdown.xml

BUILD SUCCESSFUL
Total time: 0 seconds

HOWEVER the database is not being shutdown. Its shell is still open. Can you see what is wrong here?

Ant SQL task

Thanks!

1
Have you tried ant -verbose -buildfile shutdown.xml hsqldb-stop to explicitly name the target and show feedback. - fredt
Thank you, this comment was helpful. I've explicitly added the target name hsqldb-stop to the command, as you suggested. Also, I had to explicitly state the jar file in the command path, i.e. classpath="C:\programs\hsqldb\hsqldb-2.1.0\hsqldb\lib\hsqldb.jar". Now it works. Could you tell why I had to do it this way? I thought Ant scripts being run without any specific target, simply run any target they can? Also, I thought classpath only gives the directory containing the jars, not the actual jars. - rapt

1 Answers

2
votes

It is better to name the target explicitly, as you may add extra targets later on. You can show feedback with the -verbose option for debugging.

ant -verbose -buildfile shutdown.xml hsqldb-stop

As the OP found out the jar file name must be included in the command path:

classpath="C:\programs\hsqldb\hsqldb-2.1.0\hsqldb\lib\hsqldb.jar"

The classpath in a java command is a collection of directory or jar / zip names. The names of jars and zip files must be specified specifically, as these are the compressed "directories" that contain the *.class files.