You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Neo Anderson <ja...@yahoo.co.uk> on 2008/12/28 21:23:06 UTC

classpath question

I am build a project and that looks ok at the moment. However I encounter a problem when running test. 

My problem is that I have a customized xml. So I build a test located in the test/project/name/to/xmlTest.java, in which it will load an xml file to have  a small test. The xml file is located at reousrces/project/name/to/file.xml. Unfortunately, when executing the test (via mvn package), it seems the default classpath would be the place where pom.xml exists. Therefore, if in the xmlTest.java I specify xml path like

parser.parse("project/name/to/file.xml");

The maven throws "Running project.name.xmlTest
java.io.FileNotFoundException: $HOME/path/to/pom.xml/project/name/to/file.xml (No such file or directory)"

I read the doc - http://maven.apache.org/plugins/maven-surefire-plugin/examples/additional-classpath.html; seemingly I can add additional classpath whilst running test. But no luck, it still looks up the default one. 

I am able to specify the exactly path to solve the problem. 
For instance, 

parser.parse("src/parent_name/project/name/to/file.xml"); 

where src/parent_name is the structure folder that will only be used when writing programme. But this is not what I want because I think that classpath should be configurable.

Is any way I can configure to specify the classpath in pom.xml?

Thanks in advice,












      

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


Re: classpath question

Posted by Linghua Wang <mm...@gmail.com>.
Hi,

I have not tried additional classpath feature in maven2. I am not sure
whether you load your xml file as following?

InputStream inputStream = YourClass.class. getResourceAsStream("The relative
PATH of your XML file");

Thanks.

Linghua

2008/12/28 Neo Anderson <ja...@yahoo.co.uk>

> I am build a project and that looks ok at the moment. However I encounter a
> problem when running test.
>
> My problem is that I have a customized xml. So I build a test located in
> the test/project/name/to/xmlTest.java, in which it will load an xml file to
> have  a small test. The xml file is located at
> reousrces/project/name/to/file.xml. Unfortunately, when executing the test
> (via mvn package), it seems the default classpath would be the place where
> pom.xml exists. Therefore, if in the xmlTest.java I specify xml path like
>
> parser.parse("project/name/to/file.xml");
>
> The maven throws "Running project.name.xmlTest
> java.io.FileNotFoundException:
> $HOME/path/to/pom.xml/project/name/to/file.xml (No such file or directory)"
>
> I read the doc -
> http://maven.apache.org/plugins/maven-surefire-plugin/examples/additional-classpath.html;
> seemingly I can add additional classpath whilst running test. But no luck,
> it still looks up the default one.
>
> I am able to specify the exactly path to solve the problem.
> For instance,
>
> parser.parse("src/parent_name/project/name/to/file.xml");
>
> where src/parent_name is the structure folder that will only be used when
> writing programme. But this is not what I want because I think that
> classpath should be configurable.
>
> Is any way I can configure to specify the classpath in pom.xml?
>
> Thanks in advice,
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>