How to put mapper xml outside the project.

703 views
Skip to first unread message

Piotr Kosmowski

unread,
Jun 8, 2010, 9:12:37 AM6/8/10
to mybatis-user
Is it possible to put mappers xml in outside resource? I want to be
able to change the content of the file without recompiling the project.

Piotr Kosmowski

unread,
Jun 8, 2010, 12:38:15 PM6/8/10
to mybatis-user
I will extend my question:

According to the user guide i am able to use file path instead of
resource:
// Using classpath relative resources
<mappers>
<mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
</mappers>

// Using url fully qualified paths
<mappers>
<mapper url="file:///var/sqlmaps/AuthorMapper.xml"/>
</mappers>

in my project I'm trying to put my mapper xml "outside" the project
and i'm doing this:
<mapper url="file://D:/Mappers/ComponentMapper1.xml" />

The output of my log4j console:
### Error building SqlSession.
### The error may exist in file://D:/Mappers/ComponentMapper1.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing
SQL Mapper Configuration. Cause: java.net.UnknownHostException: D

Is it bug or it's me doing something wrong?

Larry Meadors

unread,
Jun 8, 2010, 12:53:06 PM6/8/10
to mybati...@googlegroups.com
Try file:/// (3 "/" characters)? Maybe.

Larry

Chema

unread,
Jun 8, 2010, 1:56:42 PM6/8/10
to mybati...@googlegroups.com
2010/6/8 Larry Meadors <larry....@gmail.com>:

> Try file:/// (3 "/" characters)? Maybe.
>

Yes, that is the solution

The code is

URL url = new URL(urlString);
URLConnection conn = url.openConnection();

If urlString is file:///C:/namefile.log ( for example ), all works fine.
With only 2 slash (file://C:/namefile.log), an exception is thrown

java.net.UnknownHostException: C
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.NetworkClient.openServer(Unknown Source)
at sun.net.ftp.FtpClient.openServer(Unknown Source)
at sun.net.ftp.FtpClient.openServer(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(Unknown Source)

Daniel López

unread,
Jun 8, 2010, 3:07:05 PM6/8/10
to mybati...@googlegroups.com
If you put the resource in the classpath, it doesn't have to be inside
a jar file. And this way you don't have a hardcoded path that will
give you trouble if you move your application to another location.

For example, in some web applications I put the mapper files in
WEB-INF/classes and I can modify them without recompiling the java
classes or re-creating any jar file.

S!
D.

2010/6/8 Chema <demab...@gmail.com>:

Piotr Kosmowski

unread,
Jun 8, 2010, 6:06:11 PM6/8/10
to mybatis-user
Thank you so much guys. It work's and that the solution for me :)

On 8 Cze, 21:07, Daniel López <d.lope...@gmail.com> wrote:
> If you put the resource in the classpath, it doesn't have to be inside
> a jar file. And this way you don't have a hardcoded path that will
> give you trouble if you move your application to another location.
>
> For example, in some web applications I put the mapper files in
> WEB-INF/classes and I can modify them without recompiling the java
> classes or re-creating any jar file.
>
> S!
> D.
>
> 2010/6/8 Chema <demablo...@gmail.com>:
>
>
>
> > 2010/6/8 Larry Meadors <larry.mead...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages