Maven + jarsigner +测试类=错误

时间:2014-02-19 12:04:27

标签: maven junit jarsigner

我有一个包含一些测试用例的Maven项目。今天我尝试添加jarsigner插件,现在测试失败了:

java.lang.SecurityException:class“types.AccountType”的签名者信息与同一包中其他类的签名者信息不匹配

测试类在同一个包中可以访问package-private方法等。我相信这个错误正在发生,因为在测试的类中没有签署junit测试类。

有没有人建议如何避免这个问题?我有一些想法,但不知道如何实现它们:

  1. 导致测试阶段使用类而不是jar文件。
  2. 将测试类放入他们自己的jar文件中并签名。

1 个答案:

答案 0 :(得分:1)

我今天遇到了这个问题,问题出在许多年前,就像您猜到的一样(签单问题)。这是我的解决方法(更改安装阶段):

        <plugin>
            <artifactId>maven-jarsigner-plugin</artifactId>
            <version>${maven-jarsigner-plugin.version}</version>
            <executions>
                <execution>
                    <id>sign</id>
                    <!-- note: this needs to be bound after integration tests or they will fail re: not signed -->
                    <phase>install</phase>
                    <goals>
                        <goal>sign</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <tsa>http://sha256timestamp.ws.symantec.com/sha256/timestamp</tsa>
                <keystore>${project.basedir}/.conf/Keystore</keystore>
                <alias>Alias</alias>
                <storepass>{1234}</storepass>
            </configuration>
        </plugin>

Jars仍然签名,并且集成测试再次起作用。