You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Richard Bibb <ri...@aimhedge.com> on 2009/08/27 09:53:02 UTC

Maven and iBatis 3.0 - Excuse me for the stupid question

I'm probably being silly here as I don't seem to be able to figure out where
to put my sqlMap XML files in my Maven project.

Everything works fine when I just use iBatis in the main code but when I try
to ise iBatis in the unit test code iBatis cannot find the xml files for the
modules under test.

My current directory structure looks like this

src-main------     
       |          config
       |            |
       |          java......
       |            |             core
       |            |                |
       |            |             data
       |            |                      sqlmaps
       |          resources
     site
       |
     test
                  java......
                     |            core
                     |              |
                     |            data
                     |                     sqlmaps
                  resources


The sqlmap files go in the obvious directories. These files are located
using the <mappers> section in the config file.

<mapper resource="sqlmaps/someMapper.xml"/>

The problem is, when under test how do I distinguish between the Mappers
under test and those being used to do the testing? At the moment I only seem
to be able to get things to work if I put all the Mapper.xml files in the
test sqlmaps directory. Clearly this isn't good.

Can someone offer advice to a maven/iBatis novice?


-- 
View this message in context: http://www.nabble.com/Maven-and-iBatis-3.0---Excuse-me-for-the-stupid-question-tp25167237p25167237.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Rick <ri...@gmail.com>.
On Thu, Sep 3, 2009 at 7:34 AM, Andy Law <an...@roslin.ed.ac.uk> wrote:

>
> Just to clarify, the xml files don't have to be at the top-level of the
> resources folder. You can impose a directory structure inside the resources
> folder too and so have "the xml files in a directory on their own".
>

Right, I keep mine in 'src/resources/mapper-files/'

Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Andy Law <an...@roslin.ed.ac.uk>.

Richard Bibb wrote:
> 
> It turns out that this is the approach I needed to use. Putting the files
> in the resources directory works but to my mind it's untidy. Having the
> xml files in a directory on their own is better to my mind, albeit adding
> a slight non-standard aspect to my maven build
> 

Just to clarify, the xml files don't have to be at the top-level of the
resources folder. You can impose a directory structure inside the resources
folder too and so have "the xml files in a directory on their own".
Admittedly this can be a pain (replicating the package tree to be able to
have hierarchies of package.properties files in struts 2 applications is one
that springs to mind) but it can be done and it works well.

Later,

Andy
-- 
View this message in context: http://www.nabble.com/Maven-and-iBatis-3.0---Excuse-me-for-the-stupid-question-tp25167237p25274197.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Richard Bibb <ri...@aimhedge.com>.
It turns out that this is the approach I needed to use. Putting the files in
the resources directory works but to my mind it's untidy. Having the xml
files in a directory on their own is better to my mind, albeit adding a
slight non-standard aspect to my maven build

rickcr-2 wrote:
> 
> On Thu, Aug 27, 2009 at 3:07 PM, Brandon Goodin
> <br...@gmail.com>wrote:
> 
>> non .java files that belong on the classpath are supposed to go under the
>> resources directory in Maven.
> 
> 
> True. Brandon is right, you should put them there, otherwise you need to
> adjust your pom to include:
> 
>  <resource>
>                 <directory>src/main/java</directory>
>                 <filtering>true</filtering>
>                 <includes>
>                     <include>**/*.xml</include>
>                 </includes>
>             </resource>
> 
> 
> I should probably be more standard and move them to resources. I'll do it
> now:)
> 
> 

-- 
View this message in context: http://www.nabble.com/Maven-and-iBatis-3.0---Excuse-me-for-the-stupid-question-tp25167237p25254956.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Rick <ri...@gmail.com>.
On Thu, Aug 27, 2009 at 3:07 PM, Brandon Goodin <br...@gmail.com>wrote:

> non .java files that belong on the classpath are supposed to go under the
> resources directory in Maven.


True. Brandon is right, you should put them there, otherwise you need to
adjust your pom to include:

 <resource>
                <directory>src/main/java</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>


I should probably be more standard and move them to resources. I'll do it
now:)

Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Richard Bibb <ri...@aimhedge.com>.
I did start putting the .xml files in the resources directory but I don't
like clutter so I grouped them into a separate directory ant that is
probably part of the issue. I'll have a think about what I'm doing


bgoodin wrote:
> 
> non .java files that belong on the classpath are supposed to go under the
> resources directory in Maven.
> Brandon
> 
> On Thu, Aug 27, 2009 at 2:53 AM, Richard Bibb
> <ri...@aimhedge.com>wrote:
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Maven-and-iBatis-3.0---Excuse-me-for-the-stupid-question-tp25167237p25220816.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Brandon Goodin <br...@gmail.com>.
non .java files that belong on the classpath are supposed to go under the
resources directory in Maven.
Brandon

On Thu, Aug 27, 2009 at 2:53 AM, Richard Bibb <ri...@aimhedge.com>wrote:

>
> I'm probably being silly here as I don't seem to be able to figure out
> where
> to put my sqlMap XML files in my Maven project.
>
> Everything works fine when I just use iBatis in the main code but when I
> try
> to ise iBatis in the unit test code iBatis cannot find the xml files for
> the
> modules under test.
>
> My current directory structure looks like this
>
> src-main------
>       |          config
>       |            |
>       |          java......
>       |            |             core
>       |            |                |
>       |            |             data
>       |            |                      sqlmaps
>       |          resources
>     site
>       |
>     test
>                  java......
>                     |            core
>                     |              |
>                     |            data
>                     |                     sqlmaps
>                  resources
>
>
> The sqlmap files go in the obvious directories. These files are located
> using the <mappers> section in the config file.
>
> <mapper resource="sqlmaps/someMapper.xml"/>
>
> The problem is, when under test how do I distinguish between the Mappers
> under test and those being used to do the testing? At the moment I only
> seem
> to be able to get things to work if I put all the Mapper.xml files in the
> test sqlmaps directory. Clearly this isn't good.
>
> Can someone offer advice to a maven/iBatis novice?
>
>
> --
> View this message in context:
> http://www.nabble.com/Maven-and-iBatis-3.0---Excuse-me-for-the-stupid-question-tp25167237p25167237.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Rick <ri...@gmail.com>.
On Thu, Aug 27, 2009 at 3:53 AM, Richard Bibb <ri...@aimhedge.com>wrote:

>
> I'm probably being silly here as I don't seem to be able to figure out
> where
> to put my sqlMap XML files in my Maven project.
>

I put them directly in the same package where I have my XYZMapper classes,
so in your diagram I'd put them in java/data/sqlmaps right along side the
java Mappers. I name my classes like: EmloyeeMapper.java,  and then have
EmployeeMapper.xml along side it.

Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Richard Bibb <ri...@aimhedge.com>.
Thanks for your reply rickr. I'll have another look at my setup to see if I
can figure out what is going wrong. I have probably made a mistake. Just the
fact that you can do what I want tells me I have something wrong. I'll get
back to you if I get stuck 

-- 
View this message in context: http://www.nabble.com/Maven-and-iBatis-3.0---Excuse-me-for-the-stupid-question-tp25167237p25235160.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Rick <ri...@gmail.com>.
On Mon, Aug 31, 2009 at 5:57 AM, Richard Bibb <ri...@aimhedge.com>wrote:

>
> I'm not running separate sql during test and real. My problem comes from
> the
> fact that I'm trying to use iBatis to set my test data up proior to running
> the real code. (i.e. in the @BeforeClass part of my unit test). The issue I
> have is that during testing the resources seem to get loaded from
> src/test/resources and when running normally from src/main/resources. This
> means that the .xml files for the "real" code do not seem to be seen when I
> run my tests
>
>
Can you paste your pom.xml? I only have my mapper.xm files in
src/main/resources/ and they are read fine by main src daos during tests.
I'm no maven expert so I 'think' (and someone correct me if I'm wrong), your
src/main/resources always get compiled into your main classes directory
(even during tests.) The test/resources are available on the classpath
during testing but are obviously not compiled into your final build.

Are you absolutely certain that it's the xml file it's not finding and not
something else? To prove it's the xml it's not finding, take one of your xml
queries and make it as annotation on the Mapper class select itself. The run
your test that calls a dao that uses that mapper.

I think it'll help if you paste a screen shot of your exploded directory
structure and your pom.


> It's quite possible that I have something wrong here in my configuration.
> Maybe a better question would have been "How do you unit test your iBatis
> code if you use Maven?"
>
>
I just create some Test classes that call my service classes or daos that
are part of the src/main tree and they work. If you need more help let me
know.

Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Richard Bibb <ri...@aimhedge.com>.
I'm not running separate sql during test and real. My problem comes from the
fact that I'm trying to use iBatis to set my test data up proior to running
the real code. (i.e. in the @BeforeClass part of my unit test). The issue I
have is that during testing the resources seem to get loaded from
src/test/resources and when running normally from src/main/resources. This
means that the .xml files for the "real" code do not seem to be seen when I
run my tests

It's quite possible that I have something wrong here in my configuration.
Maybe a better question would have been "How do you unit test your iBatis
code if you use Maven?"


rickcr-2 wrote:
> 
> On Thu, Aug 27, 2009 at 3:53 AM, Richard Bibb
> <ri...@aimhedge.com>wrote:
> 
>>
>> The problem is, when under test how do I distinguish between the Mappers
>> under test and those being used to do the testing? At the moment I only
>> seem
>> to be able to get things to work if I put all the Mapper.xml files in the
>> test sqlmaps directory. Clearly this isn't good.
>>
>> Can someone offer advice to a maven/iBatis novice?
>>
> 
> 
> I'm a bit confused. It sounds like you want to run different SQL
> statements
> in test vs your real code? The actual SQL itself is going to change? That
> seems a bit odd at first glance to me, since I'd think the idea of the
> tests
> is to make sure that the production Mappers you wrote actually work, so
> not
> sure I'd see a case to have different ones used in test? Maybe you could
> elaborate more on it. (Actually you won't even be able to build a Mapper
> class of the same name in a test package that has the same structure. You
> could have it use a different mapper.xml file, but not the class name.)
> 
> Can you explain why you want to use different Mappers in Test from your
> real
> code?
> 
> 

-- 
View this message in context: http://www.nabble.com/Maven-and-iBatis-3.0---Excuse-me-for-the-stupid-question-tp25167237p25220912.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Maven and iBatis 3.0 - Excuse me for the stupid question

Posted by Rick <ri...@gmail.com>.
On Thu, Aug 27, 2009 at 3:53 AM, Richard Bibb <ri...@aimhedge.com>wrote:

>
> The problem is, when under test how do I distinguish between the Mappers
> under test and those being used to do the testing? At the moment I only
> seem
> to be able to get things to work if I put all the Mapper.xml files in the
> test sqlmaps directory. Clearly this isn't good.
>
> Can someone offer advice to a maven/iBatis novice?
>


I'm a bit confused. It sounds like you want to run different SQL statements
in test vs your real code? The actual SQL itself is going to change? That
seems a bit odd at first glance to me, since I'd think the idea of the tests
is to make sure that the production Mappers you wrote actually work, so not
sure I'd see a case to have different ones used in test? Maybe you could
elaborate more on it. (Actually you won't even be able to build a Mapper
class of the same name in a test package that has the same structure. You
could have it use a different mapper.xml file, but not the class name.)

Can you explain why you want to use different Mappers in Test from your real
code?