You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by hbf <fi...@inf.ethz.ch> on 2009/04/16 00:45:18 UTC
Mvn test: how to get classpath when starting another VM?
Dear list,
I have a unit test that uses Java's Runtime.exec() method to start another
VM and execute code in it. I need this to test recovery from simulated power
failure. The code that should run in the VM is a test case itself, from the
same project. I do not know what classpath to pass to the exec command:
Runtime.exec("java -classpath "\"" + System.getProperty("java.class.path")
+ "\" " + MyUnitTest.getCanonicalName());
This works from within Eclipse but not if I do a 'mvn test'.
How can I obtain a classpath from Maven that I can use to start the separate
VM?
Thanks for any pointers,
Kaspar
P.S. What I want to do is write a unit test that runs some code which
simulates a power failure by calling System.exit(). Then the unit test
continues by restarting the app and checking that recovery works. To
accomplish this, I wrote a unit test that uses – as described above
– Runtime.exec() to launch the code that does some work and then exit()'s.
But I don't manage get this to run due to the above classpath issues.
--
View this message in context: http://www.nabble.com/Mvn-test%3A-how-to-get-classpath-when-starting-another-VM--tp23068442p23068442.html
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Mvn test: how to get classpath when starting another VM?
Posted by Nick Stolwijk <ni...@gmail.com>.
I don't know if this is working, but give it a try:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<systemProperties>
<property>
<name>myClasspath</name>
<value>${classpathElements}</value>
</property>
</systemProperties>
</configuration>
</plugin>
And then in your code:
System.getProperty("myClasspath")
Perhaps you have to do some postprocessing on the String, but this is
how the maven-surefire-plugin gets it classpath.
http://svn.apache.org/viewvc/maven/surefire/tags/surefire-2.4.3/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?view=markup
Hth,
Nick Stolwijk
~Java Developer~
Iprofs BV.
Claus Sluterweg 125
2012 WS Haarlem
www.iprofs.nl
On Thu, Apr 16, 2009 at 12:45 AM, hbf <fi...@inf.ethz.ch> wrote:
> System.getProperty("java.class.path")
> + "\" " + MyUnitTest.getCanonicalName());
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org