문제

I would like to build a JUnit integration test that launches a Java process (Spring based) and then makes calls against that process.

If I would call this from the command line I would launch the Java process by calling mvn exec:java -DmainClass=myClass -Dblahblah from the command line in my pom directory

Is there any way to call that exec:main from inside my Java tester class, so that my tester can execute calls against process and validate results?

도움이 되었습니까?

해결책 2

You can use maven-invoker

Here is the what you need

InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( "/path/to/pom.xml" ) );
request.setGoals( Collections.singletonList( "exec:java -DmainClass=com.vgrazi.MyClass -Dparam1=value1" ) );

Invoker invoker = new DefaultInvoker();
invoker.execute( request );

다른 팁

Use the Maven invocation API

The code is going to be something similar to the following:

InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( "/path/to/pom.xml" ) );
request.setGoals( Collections.singletonList( "install" ) );

Invoker invoker = new DefaultInvoker();
invoker.execute( request );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top