如何使用maven部署带有依赖jar的Applet并对其进行签名?

发布于 2024-08-17 04:50:12 字数 91 浏览 3 评论 0原文

有人可以告诉我 pom 文件应该是什么样子来创建一个带有小程序的 jar 文件,该文件依赖于其他一些 jar 是否可以将一个 jar 作为小程序,以及如何对其进行签名?

Can someone show me how pom file should look like to create a jar file with applet which depends from some other jars is it possible to have one jar as applet, and how to sign it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_蜘蛛 2024-08-24 04:50:12

如果您希望您的类依赖项出现在一个jar文件中,您应该使用程序集插件one-jar 插件位于 jarsigner 之前。我对程序集插件进行了以下工作设置,它将生成正常的(签名的)jar 和 ${artifactId}-${version}-jar-with-dependency.jar (也签名)。

            <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <index>true</index>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-my-applet-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jarsigner-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                    <id>sign</id>
                    <goals>
                        <goal>sign</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <keystore>keystore</keystore>
                <alias>keyalias</alias>
                <storepass>storepass</storepass>
                <keypass>keypass</keypass>
            </configuration>
        </plugin>

If you would like your classes and the dependencies to appear in one jar file, you should use either the assembly plugin or the one-jar plugin before the jarsigner. I have the following working setup with the assembly plugin, it will produce the normal (signed) jar and a ${artifactId}-${version}-jar-with-dependencies.jar (also signed).

            <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <index>true</index>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-my-applet-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jarsigner-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                    <id>sign</id>
                    <goals>
                        <goal>sign</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <keystore>keystore</keystore>
                <alias>keyalias</alias>
                <storepass>storepass</storepass>
                <keypass>keypass</keypass>
            </configuration>
        </plugin>
偏爱自由 2024-08-24 04:50:12

这是小程序的示例 pom,依赖于其他(签名的)jar。您的小程序模块的代码将被打包到 jar 中并使用测试密钥进行签名。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <artifactId>parent</artifactId>
    <groupId>com.example</groupId>
    <version>0.1</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>applet</artifactId>
  <version>0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>com.example.applet</name>
  <build>
    <finalName>${artifactId}-${version}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jarsigner-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>sign</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <keystore>src/main/keystore/signing-jar.keystore</keystore>
              <alias>applet</alias>
              <storepass>applet</storepass>
              <keypass>applet</keypass>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>other</artifactId>
      <version>0.4</version>
    </dependency>
  </dependencies>
</project>

这是创建密钥存储的示例 shell 脚本(将其放置在 pom 文件所在的位置并运行):

#!/bin/sh
KEYSTORE=src/main/keystore/signing-jar.keystore
keytool -genkey -alias applet -keystore $KEYSTORE -storepass applet -keypass applet -dname "CN=developer, OU=group 3, O=com.example, L=Somewhere, ST=Germany, C=DE"
keytool -selfcert -alias applet -keystore $KEYSTORE -storepass applet -keypass applet

mvn 打包后,您将拥有签名的 com.example.applet-0.1-SNAPSHOT.jar。将其与您的依赖项 (com.example.other-0.4.jar) 一起放入您的 Web 应用程序中。

This is sample pom for applet with dependency on other (signed) jar. Code of your applet module will be packaged into jar and signed using test key.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <artifactId>parent</artifactId>
    <groupId>com.example</groupId>
    <version>0.1</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>applet</artifactId>
  <version>0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>com.example.applet</name>
  <build>
    <finalName>${artifactId}-${version}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jarsigner-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>sign</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <keystore>src/main/keystore/signing-jar.keystore</keystore>
              <alias>applet</alias>
              <storepass>applet</storepass>
              <keypass>applet</keypass>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>other</artifactId>
      <version>0.4</version>
    </dependency>
  </dependencies>
</project>

This is sample shell script to create key store (place and run it where your pom file is located):

#!/bin/sh
KEYSTORE=src/main/keystore/signing-jar.keystore
keytool -genkey -alias applet -keystore $KEYSTORE -storepass applet -keypass applet -dname "CN=developer, OU=group 3, O=com.example, L=Somewhere, ST=Germany, C=DE"
keytool -selfcert -alias applet -keystore $KEYSTORE -storepass applet -keypass applet

After mvn package you will have your signed com.example.applet-0.1-SNAPSHOT.jar. Place it together with your dependency (com.example.other-0.4.jar) in your web-application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文