Tôi chỉ cần làm một thử nghiệm đơn giản với cấu hình Plugin sau tuyên bố trong một POM:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>my-exec-java</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
...
</plugins>
...
</build>
</project>
Và lớp Java sau:
package com.example;
public class Main {
public static void main(String[] args) {
throw new RuntimeException("A problem occured");
}
}
Và đây là những gì tôi nhận được khi triệu gọi integration-test
giai đoạn:
$ mvn clean integration-test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building q2363055
[INFO] task-segment: [clean, integration-test]
[INFO] ------------------------------------------------------------------------
...
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: /home/pascal/Projects/stackoverflow/q2363055/target/q2363055-1.0-SNAPSHOT.jar
[INFO] Preparing exec:java
[WARNING] Removing: java from forked lifecycle, to prevent recursive invocation.
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: my-exec-java}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. null
A problem occured
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19 seconds
[INFO] Finished at: Tue Mar 02 23:40:32 CET 2010
[INFO] Final Memory: 16M/79M
[INFO] ------------------------------------------------------------------------
integration
giai đoạn không bao giờ được thực hiện, vì lỗi xây dựng.
Vì vậy, câu hỏi đặt ra là, bạn xử lý các lỗi trong lớp Java tải db của bạn như thế nào? Là ném một ngoại lệ một lựa chọn?
Nguồn
2010-03-02 22:46:27
là có thể sử dụng exec: exec, trong trường hợp đó tôi đoán bạn có thể sử dụng mã trả lại? –