Cóż, trzeba włączyć exec-maven-plugin
ten plug-in, wykonuje to samo, co robisz w wierszu poleceń po wpisaniu w java -cp .;jarpaths TestMain
. Możesz przekazać argument i zdefiniować fazę (test
, package
, integration
, lub deploy
), aby ta wtyczka wywoływała twoją główną klasę.
Musisz dodać tę wtyczkę pod tagiem <build>
i określić parametry. Na przykład
<project>
...
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>my.company.name.packageName.TestMain</mainClass>
<arguments>
<argument>myArg1</argument>
<argument>myArg2</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
...
</project>
Teraz, jeśli kliknąć prawym przyciskiem myszy na folderze projektu i zrobić Run As > Maven Test
lub Run As > Maven Package
lub Run As > Maven Install
The test phase
wykona i tak swoje główne klasy.