java - Dynamically set Maven Surefire JVM classpath -


i'm trying add jvm classpath argument when running our maven unit tests adding following maven arguments, "dir" replaced desired clasaspath.

maven_opts = -cp "dir"

this correctly get's added java arguments

yet "dir" never correctly added classpath. desired file in classpath never found, , missing when printing out classpath with

classloader cl = classloader.getsystemclassloader(); url[] urls = ((urlclassloader)cl).geturls(); 

there's difference between jvm run maven , jvm in use when running tests.

the surefire plugin spawn own jvm run test case(s). default, include following on jvm's classpath:

  • your project's classes directory
  • your project's test-classes directory
  • your project's dependencies.

if have understood question correctly want add directory classpath jvm running test(s). if so, can add additional classpath entry so:

<plugin>     <groupid>org.apache.maven.plugins</groupid>     <artifactid>maven-surefire-plugin</artifactid>     <version>2.20</version>     <configuration>       <additionalclasspathelements>         <additionalclasspathelement>path/to/your/additional/directory</additionalclasspathelement>       </additionalclasspathelements>     </configuration> </plugin> 

more details here.

if want dynamically change classpath used surefire jvm via command line parameter (as mention of maven_opts implies) define additionalclasspathelement ...

<additionalclasspathelement>${additionalclasspathdir}</additionalclasspathelement> 

... , invoke maven this:

mvn test -dadditionalclasspathdir=path/to/your/additional/directory 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -