On Mon, 26 Sep 2005, Dhananjay Nene wrote:

There's nothing wrong here. The system property java.class.path is
the classpath for the JVM, i.e. the CLASSPATH environment variable
when you start the jvm.

What you need/want is the 'classpath' of the classloader that runs
the tests: Thread.currentThread().getContextClassLoader(). That
classloader has a larger classpath, although it's hard to get the
classpath string from it. If you really need to, use this snippet
of code:

    public List getRuntimeClasspath()
        throws IOException
    {
        List classpathEntries = new ArrayList();

        Enumeration n = 
Thread.currentThread().getContextClassLoader().getResources( "META-INF" );

        while ( n.hasMoreElements() )
        {
            URL url = (URL) n.nextElement();

            String path = url.getPath();

            int idx = path.indexOf( "!" );
            path = (idx > 0) ? path.substring(0, idx) : path;

            URL url2 = new URL(path);

            path = url2.getFile();

            classpathEntries.add( path );
        }

        return classpathEntries;
    }


But normally you'd use ClassLoader.getResource().

-- Kenney


> I am unable to figure out why when I run m2 with a test target the
> tests are executed with a nearly empty classpath. I have setup all my
> dependencies with the appropriate compile or test scope but these
> are are not being reflected in the classpath during execution. e.g. I
> added the following to my test case :
>
> System.out.println("--------------------------------------------------------------------");
> System.out.println(System.getProperty("java.class.path"));
> System.out.println("--------------------------------------------------------------------");
>
> Here's what I get in the output
> --------------------------------------------------------------------
> /usr/local/maven/core/boot/classworlds-1.1-alpha-2.jar
> --------------------------------------------------------------------
>
> My relevant <plugin> snippet in pom.xml is as follows :
>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-surefire-plugin</artifactId>
>                 <executions>
>                     <execution>
>                         <phase>test</phase>
>                     </execution>
>                 </executions>
>                 <goals>
>                     <goal>
>                         <id>test</id>
>                         <configuration>
>                             <!--
>                             <test>**/Test*</test>
>                             -->
>                             <includes>
>                                 <include
> implementation="java.lang.String">**/Test*</include>
>                             </includes>
>                         </configuration>
>                     </goal>
>                 </goals>
>             </plugin>
>
> Any suggestions what could be going wrong ?
>
> Thanks
> Dhananjay
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

--
Kenney Westerhof
http://www.neonics.com
GPG public key: http://www.gods.nl/~forge/kenneyw.key

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to