Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start launch the HSQLDB server as described in the Hibernate tutorial?

Trying to follow step #4 in this Hibernate tutorial:

mvn exec:java -Dexec.mainClass="org.hsqldb.Server" -Dexec.args="-database.0 file:target/data/tutorial"

I am getting this error:

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[INFO] Building First Hibernate Tutorial
[INFO]    task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default-cli}]
[WARNING]
java.lang.ClassNotFoundException: org.hsqldb.Server
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
        at java.lang.Thread.run(Thread.java:662)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. org.hsqldb.Server

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Mon Dec 17 16:35:42 EST 2012
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------

This is despite downloading the latest hsqldb package and installing it per the FAQ. The hsqldb.jar file is located in C:\hsqldb-2.2.9\hsqldb-2.2.9\hsqldb\lib and the classpath env var points at it:

CLASSPATH=C:\hsqldb-2.2.9\hsqldb-2.2.9\hsqldb\lib

So why am I receiving this ClassNotFoundException: org.hsqldb.Server error?

What am I doing wrong?

like image 950
Withheld Avatar asked Dec 17 '12 21:12

Withheld


2 Answers

First of all, your CLASSPATH is not generally correct for any jar. A jar name must be specified, for example:

CLASSPATH=C:\hsqldb-2.2.9\hsqldb-2.2.9\hsqldb\lib\hsqldb.jar

Second, CLASSPATH is not necessary for this tutorial, as it is a Maven project. You should add the relevant dependency to the pom.xml file that is described in section 1.1.1 of the tutorial you mention. Simply add this block to the ones listed in the pom.xml, inside the tab:

<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>2.2.9</version>
</dependency>
like image 79
fredt Avatar answered Oct 02 '22 19:10

fredt


According to http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html, you need to specify the whole path ending with .jar. If there are multiple jar files, maybe try specifying C:\path\to\hibernate*.jar

If you only specify directories, only *.class files are loaded.

Other possiblity is the CLASSPATH variable you set only valid for a shell session, not globally -- hence the maven command is not reading it. Try setting it via Windows system settings.

like image 24
gerrytan Avatar answered Oct 02 '22 19:10

gerrytan