如何将多个罐子的人? [英] How to Combine Multiple Jars into One?

查看:164
本文介绍了如何将多个罐子的人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这看了这么多文章/解释,花了太多时间,但一切不是太广泛或具体。

I've read so many articles/explanations on this and spent too many hours, but everything is either too broad or specific.

这个问题确实只适用于我做了一个Applet。它包含一个类,并要求其他2瓶库。我已经包含这些在项目(多个项目,因为我已经在Eclipse和Netbeans尝试过这...这是很容易重新创建一个类项目)。所有这一切的一点是,我的HTML / Web项目不应该处理一个以上的JAR或引用它们。这不是一个复杂的小程序/项目都无论是。

This question really only applies to an Applet I've made. It contains one Class, and requires 2 other Jar libraries. I've included these in the projects (multiple projects, because I've tried this in Netbeans and Eclipse...it's easy to recreate a one Class project). The point of all this is that my HTML/web project shouldn't have to deal with more than one Jar or reference them. It's not a complicated applet/project at all either.

本来,我在Netbeans的做到了。它有主包,并添加了2瓶后,他们被放在一个库区域(资源文件夹)。建设后,Netbeans的创建我的一个封装/类罐,然后放2其他图书馆的lib目录旁边。我想他们是在一个,分发的JAR。从很多事情我已经经历看,我试图把build.xml中的以下内容:

Originally, I made it in Netbeans. It has the main package, and after adding the 2 Jars, they are put in a "Libraries" area (the "resources" folder). After building it, Netbeans creates a Jar for my one package/class, and then puts the 2 other libraries in a "lib" directory next to it. I'd like them to be in one, distributable Jar. From the many things I've looked through, I've tried putting the following in build.xml:

<target name="YourBigJar" depends="-post-jar">
  <jar destfile="dist/BigJar.jar">
    <zipfileset src="dist/cxapplet.jar"/>
    <zipfileset src="resources/dpotapi.jar"/>
    <zipfileset src="resources/dpotjni.jar"/>
  </jar>
</target>

但它产生什么。我得到这个从 NetBeans的 - 在一个罐子部署。我不知道/了解如何使用build.xml文件,所以如果有什么地方出了错(显然)我不会感到惊讶,但我没有得到任何错误/警告消息。

But it produces nothing. I got this from NetBeans - deploying all in one jar . I don't know/understand how to use build.xml, so I wouldn't be surprised if something's going wrong (obviously), but I get no error/warning messages.

当我在Eclipse中做它,它有效地结合他们,但是当我用瓶子在我实际的Web项目,它说,它不能从其他2罐发现的类。我不知道如何解决它,但它是一个classpath的问题吗?在Eclipse中,我做了一个名为LIB新目录,并把罐子在里面。然后,我用鼠标右键单击该项目,进入Java构建路径,并添加罐,还检查他们的排序和导出选项卡下。从东西我读过,我右键单击该项目,选择导出,选择瓶,取消选中的.classpath和的.project文件,只选择导出生成的类文件和资源,然后允许它来生成清单文件。就像我说的,这生成一个瓶子,但它的内容是我的包中,然后在其他2罐一个lib目录。该清单是存在的,但它是pretty空的,没有引用任何文件(不知道这是很重要的)。当我把它放在我的web应用程序,它说小程序无法找到其他类。

When I made it in Eclipse, it effectively combines them, but when I use the Jar in my actual web project, it says it cannot find the classes from the other 2 Jars. I wouldn't understand how to fix it, but is it a Classpath problem? In Eclipse, I make a new directory called "lib" and put the Jars in it. Then, I right-click the project, go to "Java Build Path", and add the Jars, also checking them under the "Order and Export" tab. From things I've read, I right-click the project, choose "Export", choose "Jar", uncheck the ".classpath" and ".project" files, only check "Export generated class files and resources", and then allow it to generate the manifest file. Like I said, this generates one Jar, but its contents are my package and then a "lib" directory that has the 2 other Jars. The Manifest is there, but it's pretty empty and doesn't reference any files (not sure if that's important). When I put it in my web app, it says the applet can't find the other classes.

它只是似乎很简单 - 一个封装/班,两个外部罐......合并成一个罐子时分发的applet建成。任何想法?

It just seems so simple - one package/class, two external Jars...combine into one Jar when built for distribution as an applet. Any ideas?

更新:

自从我们开始使用Maven,有人看着使用Maven插件。因此,我们结束了创建一个新的项目来容纳小程序(因为它在多个项目中使用),并用这种我们的的pom.xml ,中底:

Since we started using Maven, someone looked into using a Maven plugin. So we ended up creating a new project to house the applet (since it's used across multiple projects), and used this in our pom.xml, in the end:

<build>
  <resources>
    <resource>
      <directory>${basedir}/applet</directory>
      <excludes>
        <exclude>codesignstore</exclude>
      </excludes>
    </resource>
    <resource>
      <directory>${basedir}/src/main/resources</directory>
      <filtering>true</filtering>
    </resource>
  </resources>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.2-beta-5</version>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <finalName>cxapplet</finalName>
        <archive>
          <index>true</index>
          <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
          </manifest>
        </archive>
        <appendAssemblyId>false</appendAssemblyId>
      </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>${basedir}/applet/codesignstore</keystore>
        <alias>codesigncert</alias>
        <storepass>HIDDEN</storepass>
        <keypass>HIDDEN</keypass>
      </configuration>
    </plugin>
  </plugins>
</build>

和,因为它允许我们使用我们的code签名证书自动登录它也很高兴。

And it was nice because it allowed us to use our Code Signing Certificate to automatically sign it too.

推荐答案

首先,让我说,实在是没有理由的罐子结合 - 您可以使用类文件(而不是在一个罐子)部署一个applet其独立的依赖jar文件。

First of all, let me say that there really is no reason to combine the jars - you can deploy an applet using your class file (not in a jar) and its separate dependent jars.

不过,如果你觉得你必须做出一个大罐子你的类和所有的依赖,那么你可以这样做。

However, if you feel that you must make one big jar out of your class and all of its dependencies, then you can do so.

您不能把jar文件到另一个jar文件,但是 - jar文件不工作的方式。
你需要的是所有的所有jar文件的内容提取出来,然后再压缩成的一个jar文件。

You can't put jar files into another jar file, however - jar files don't work that way. What you need is for all of the contents of all of the jar files to be extracted, and then zipped up again into one jar.

如果你要做到这一点,我会建议使用 Maven的构建工具来做到这一点。
一旦您设置使用Maven构建,可以配置href=\"http://maven.apache.org/plugins/maven-assembly-plugin/\">的Maven Assembly插件来构建一个大罐子

If you're going to do this, I would suggest using the Maven build tool to do it. Once you set up your build with Maven, you can configure the Maven Assembly Plugin to build one big jar for you.

我知道Eclipse支持Maven的,我认为NetBeans的确实也是如此。

I know that Eclipse supports Maven, and I assume that NetBeans does as well.

这篇关于如何将多个罐子的人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆