Classpath problem with mybatis generator 1.3.5

427 views
Skip to first unread message

Carsten Langsdorf

unread,
Feb 9, 2017, 6:29:30 PM2/9/17
to mybatis-user
Hello everyone,

I'm just trying to take first steps with mybatis - seems a very promising approach. Thus, I created a nice configuration file for the generator:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

   
<properties resource="database.properties"/>

   
<classPathEntry location="${driver.path}"/>

   
<context id="ODDloot" targetRuntime="MyBatis3">

       
<jdbcConnection driverClass="${driver.class}" connectionURL="${database.url}">
           
<property name="userId" value="${database.username}"/>
           
<property name="password" value="${database.password}"/>
       
</jdbcConnection>

       
<javaTypeResolver>
           
<property name="forceBigDecimals" value="false"/>
       
</javaTypeResolver>

       
<javaModelGenerator targetPackage="db.batis" targetProject="\ODDloot\src">
           
<property name="enableSubPackages" value="true"/>
           
<property name="trimStrings" value="true"/>
       
</javaModelGenerator>

       
<sqlMapGenerator targetPackage="db.batis" targetProject="\ODDloot\src">
           
<property name="enableSubPackages" value="true"/>
       
</sqlMapGenerator>

       
<javaClientGenerator type="ANNOTATEDMAPPER" targetPackage="db.batis" targetProject="\ODDloot\src">
           
<property name="enableSubPackages" value="true"/>
       
</javaClientGenerator>

       
<table schema="BASE" tableName="SERVER">
           
<property name="useActualColumnNames" value="true"/>
       
</table>

   
</context>

</generatorConfiguration>

It's basically set up just like the example given here: http://www.mybatis.org/generator/configreference/xmlconfig.html

However, I am trying to use a seperate roperties file to store the database and driver information, as you can see in this line:

<properties resource="database.properties"/>

And now, I am trying to run the generator from the command line (Win10 64 bit), also just as suggested here: http://www.mybatis.org/generator/quickstart.html

And this is what I get as a result:

<properties> resource database.properties does not exist

The properties file resides in the same directory as the configuration file, as well as a copy of the generator itself - since this is just supposed to be a first test.

Here is what I already tried:
  • Specifying the classpath via -cp
  • Using full and relative paths in the configuration file to point to the property file
  • Even using a full URL in the configuration file
Whatever I try as a workaround, the properties file cannot be located, although the error message reflects the exact location given in the configuration file.

Any idea what I might be missing or doing wrong? Any help greatly appreciated.

Cheers,
Carsten

Carsten Langsdorf

unread,
Feb 9, 2017, 6:38:54 PM2/9/17
to mybatis-user
P.S.: Well, I assume it's a classpath problem. Additional information: I am running on jdk1.8.0_121.

Iwao AVE!

unread,
Feb 10, 2017, 12:02:56 AM2/10/17
to mybatis-user
Hi Carsten,

URL should work.
Did you change the attribute name from 'resource' to 'url' when you tried?
I just did a quick test and the below worked on Win 10 (64 bit).
<properties url="file:///C:\...\database.properties"/>

'resource' may not work with command line execution as -cp is ignored when -jar is specified.

Hope this helps,
Iwao


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carsten Langsdorf

unread,
Feb 10, 2017, 9:15:29 AM2/10/17
to mybatis-user
Hi Iwao,

thanks for your help. Indeed, I had forgotten to change 'resource' to 'url' - my mistake, sorry. Using a full URL works now, although it's a bit awkward.

Considering that 16 year old issue you were linking (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4459663): It was not confirmed as a bug, but classified as a RFE, and I'm really wondering if it's still working that way.

Anyway, thanks a lot again for your help,
Carsten
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.

Iwao AVE!

unread,
Feb 11, 2017, 4:16:07 AM2/11/17
to mybatis-user
Glad to know URL worked!

It still works the same way in Java 8, it seems.

> When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored.

// Iwao

To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user+unsubscribe@googlegroups.com.

Carsten Langsdorf

unread,
Feb 11, 2017, 6:50:31 AM2/11/17
to mybatis-user
Hi Iwao,

thanks again for your help.

> When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored.

Good to know.

Cheers,
Carsten 
Reply all
Reply to author
Forward
0 new messages