将外部类导出到 JAR - Eclipse

发布于 2024-08-21 19:36:17 字数 454 浏览 8 评论 0原文

我的项目所需的类文件很少。我已将它们添加到源文件夹本身的适当文件夹结构中。我的限制是我必须提供包含所有依赖类的单个 jar 文件。它不能是可执行的 jar 文件。

现在我面临的问题是,当我在 eclipse 中选择导出来导出 jar 文件时,我没有获取在源文件夹中添加的类文件(.class),进行导出。它们甚至没有列在包资源管理器中。我怎样才能做到这一点?需要修改任何导出设置吗?

说实话,我的项目是这样的

project
     src
       com
         test
            file1.java
            file2.java
          external
            class1.class
            class2.class

现在我希望将我的源文件生成的类和我自己添加的类文件全部导出到jar中。

I have few class files that are required for my project. I have added them in the source folder itself in appropriate folder structure. My limitation is that I have to deliver a single jar file with all dependent classes. It cannot be an executable jar file.

Now the problem I am facing is that when I selected export in eclipse to export the jar file, I am not getting the class files (.class) I have added in source folder, getting exported. They are not even getting listed in the package explorer. How can I acheive this? any export setting need to be modified?

To be pricise, my project is like this

project
     src
       com
         test
            file1.java
            file2.java
          external
            class1.class
            class2.class

Now I want the generated classes for my source files and the class files that I have added myself all to be exported into the jar.

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

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

发布评论

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

评论(5

多情出卖 2024-08-28 19:36:17

也许您需要 导出可运行的 JAR 文件

编辑:如果你有很多依赖项,那么 jar 收缩器/混淆器是你最好的朋友。请参阅 ProguardyGuard。对于 Proguard,有一个 Eclipse 插件。或者您可以使用 Ant 手动集成它们中的任何一个。

Maybe you need to export Runnable JAR file?

Edit: If you have a lot of dependencies, then a jar shrinker/obfuscator is your best friend. See Proguard or yGuard. For Proguard, there is an Eclipse plugin. Or you can use Ant to integrate either of them manually.

醉南桥 2024-08-28 19:36:17

首先,我不确定如果您的类不在代表其包的各自目录中,它们是否可以工作。

即然后

project
     src
       com
         test
            file1.java
            file2.java
          external
            org
              extproject
                subpackage
                  class1.class
                  class2.class

,我宁愿尝试添加一个 链接文件夹 引用这些类的根目录,并在将项目导出到 Jar 时选择该文件夹。

project
     src
       com
         test
            file1.java
            file2.java
     org (linked to c:/another/path/to/ext/project/classes)
       extproject
         subpackage
            class1.class
            class2.class

First, I am not sure your classes could work if they are not in their respective directory representing their packages.

I.e.

project
     src
       com
         test
            file1.java
            file2.java
          external
            org
              extproject
                subpackage
                  class1.class
                  class2.class

Then, I would rather try to add a linked folder referencing the root directory of those classes, and select that folder when exporting the project to a Jar.

project
     src
       com
         test
            file1.java
            file2.java
     org (linked to c:/another/path/to/ext/project/classes)
       extproject
         subpackage
            class1.class
            class2.class
枕梦 2024-08-28 19:36:17

每当我实现需要交付给客户的应用程序时,我都会包含某种构建脚本,用于从命令行构建发行版。例如,Ant“build.xml”文件、Maven“pom.xml”文件甚至 Makefile。为了处理您的特定情况,该脚本将包括一个步骤,将所有相关类组装到临时目录树中,并从中创建发行版 JAR 文件。

我不喜欢依赖某些 IDE 的变幻莫测来进行生产构建。

Whenever I implement an application that needs to be delivered to a customer, I include a build script of some kind for building the distribution from the command line. For example, an Ant "build.xml" file, a Maven "pom.xml" file or even a Makefile. To deal with your particular situation, the script would include a step that assembled all the relevant classes into a temporary directory tree and created the distro JAR file from it.

I don't like to be dependent on the vagaries of some IDE for doing production builds.

画中仙 2024-08-28 19:36:17

我会使用 Maven 和 Maven Assembly Plugin - 这使得它非常简单制作一个带有依赖项的 jar - 甚至是一个可执行的 jar。

缺点是需要花一些时间来学习如何充分利用 Maven,但是一旦您更改了项目以使用它,您会发现生活变得更加简单。当您使用 Eclipse 时,我可以推荐这个插件:M2 Eclipse 插件

I would use Maven and the Maven Assembly Plugin - this makes it really easy to make a jar with dependencies - or even an executable jar.

The downside is that it takes a while to learn how to make the most of Maven - but you will find life much simpler once you have altered your project to use it. As you are using Eclipse I can reccomend this plugin: M2 Eclipse Plugin

影子是时光的心 2024-08-28 19:36:17

src 文件夹通常不用于保存 .class 文件。 Eclipse 会查找已构建的 .class 文件并创建 jar 文件。因此,您可以将外部 .class 文件添加到项目下的“lib 或其他”文件夹中。然后构建项目并导出 jar 文件。您将看到 jar 文件现在包含一个名为 lib 或其他名称的文件夹以及其中的外部 .class 文件。

The src folder normally is not used to keep the .class files. Eclipse looks to already built .class files and create the jar file. Therefore you can add your external .class files into a "lib or something else" folder under your project. Then build your project and export the jar file. you will see that the jar file now contains a folder named lib or something else and your external .class files in it.

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