You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Mark D. Hansen" <ma...@gmail.com> on 2005/03/03 01:03:57 UTC

adding a jar to the unit test classpath

I'm using XmlBeans to generated some Java/XML binding classes that get used in my junit tests.  The way XmlBeans works, these classes end up in a jar named "xmltypes.jar".

I can list xmltypes.jar as a dependency because it doesn't exist at the time that I invoke "maven test".  So, how do I get it on the junit testing classpath?  I tried this:

    <unitTest>
	....
	<resource> 
	  <directory>${basedir}/target/work/lib</directory> 
	  <includes>
	    <include>xmltypes.jar</include>
	  </includes>
	</resource> 
      </resources>
    </unitTest>

But it doesn't work.  Any ideas?  Is there a "standard" way to deal with this issue in Maven?

-- Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: adding a jar to the unit test classpath

Posted by "Craig S. Cottingham" <cr...@cottingham.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mar 2, 2005, at 18:03, Mark D. Hansen wrote:

> I'm using XmlBeans to generated some Java/XML binding classes that get 
> used in my junit tests.  The way XmlBeans works, these classes end up 
> in a jar named "xmltypes.jar".

The trick, at least for me, is to unpack the jar into the target/ 
directory. Some caveats for what follows. My copy of XmlBeans was built 
from a CVS snapshot from 2004-01-22. Also, I realize that some of the 
directories could be defined more portably. This works for me, and I 
haven't had to change it since. Note that the XSchema source files are 
in ${basedir}/src/schemata.

   <preGoal name="java:compile">
     <attainGoal name="xsd:compile" />
   </preGoal>

   <goal name="xsd:compile">
     <ant:taskdef name="xmlbean"
                  classname="org.apache.xmlbeans.impl.tool.XMLBean">
       <ant:classpath>
         <ant:path refid="maven.dependency.classpath" />
       </ant:classpath>
     </ant:taskdef>

     <ant:mkdir dir="${basedir}/target/classes" />

     <ant:xmlbean destfile="${basedir}/target/my-xmlbeans.jar">
       <ant:classpath>
         <ant:path refid="maven.dependency.classpath" />
       </ant:classpath>
       <ant:fileset dir="${basedir}/src/schemata">
         <ant:include name="**/*.xsd" />
       </ant:fileset>
     </ant:xmlbean>

     <ant:unjar src="${basedir}/target/my-xmlbeans.jar"
                dest="${basedir}/target/classes" />

     <ant:delete file="${basedir}/target/my-xmlbeans.jar" />
   </goal>

> So, how do I get it on the junit testing classpath?

I'd guess you would want to unjar to ${basedir}/target/test-classes.

- --
Craig S. Cottingham
craig@cottingham.net
OpenPGP key available from:
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x7977F79C
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCJliXEJLQ3Hl395wRAq27AKCCq1V6eoUo3Fudb7xyRuKfdHwmxACgyhbk
g+hqZRtHQUYuCZdse7UAP9U=
=j/Pp
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org