简体   繁体   English

如何在Eclipse MARS中制作.jar文件

[英]how to make .jar file in Eclipse MARS

I'm learning Hadoop under VMware now.(win7, 64) Due to some reason, I can't convert a .java file to .jar file under virtual machine, so I tried to create .jar file under Eclipse. 我现在正在VMware下学习Hadoop。(win7,64岁)由于某种原因,我无法在虚拟机下将.java文件转换为.jar文件,因此我尝试在Eclipse下创建.jar文件。

I'm currently using Eclipse MARS(4.5.1). 我当前正在使用Eclipse MARS(4.5.1)。 I need to download something about fat jar, but I can't find it online. 我需要下载有关胖子罐的内容,但无法在线找到它。

My colleague copied his Eclipse software to me. 我的同事向我复制了他的Eclipse软件。 It is already installed, so I copied the whole package. 它已经安装了,所以我复制了整个程序包。 It is Eclipse Kepler. 是Eclipse开普勒。 So I am running two Eclipse software on my computer now. 因此,我现在在计算机上运行两个Eclipse软件。 will this cause some problem? 这会引起一些问题吗? (I saved projects seperately) (我分别保存了项目)

I can do the convert .jar file thing correctly on Eclipse Kepler now. 我现在可以在Eclipse Kepler上正确地执行convert .jar文件了。 But I still want to use MARS and delete the extra Eclipse. 但是我仍然想使用MARS并删除多余的Eclipse。

thank you ! 谢谢 !

select project 选择项目

select Export

Expand the Java node and select JAR file. Click Next

In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field

. Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source 选择适当的复选框以指定是要导出生成的类文件和资源,还是要导出Java源代码

or go to http://www.codejava.net/ides/eclipse/how-to-create-jar-file-in-eclipse 或转到http://www.codejava.net/ides/eclipse/how-to-create-jar-file-in-eclipse

What you're looking for is the "Fat JAR" eclipse plugin. 您正在寻找的是“ Fat JAR” eclipse插件。
Fat jar is a jar which contains all the classes used by the project including their referenced dependencies. Fat jar是一个jar,其中包含项目使用的所有类,包括其引用的依赖项。
The plugin can enable the creation of such a jar. 该插件可以启用此类jar的创建。
In your case, however, Eclipse "Mars" & Eclipse "Kepler" include this functionality. 但是,就您而言,Eclipse“ Mars”和Eclipse“ Kepler”包含此功能。 The trick is to get to it... 诀窍是去实现它...
Here's what you do in order to export a Fat JAR: 以下是导出Fat JAR的操作:

  1. Right-click on the required Project and select " Export... " --> " Runnable JAR file ". 右键单击所需的项目,然后选择“ 导出...-> “可运行的JAR文件 ”。
  2. Select the option which extracts libraries and specify the destination JAR file. 选择提取库的选项并指定目标JAR文件。
  3. Launch configuration is used to execute this JAR with a predefined "Main" class (this is the "Runnable" part...) using "java -jar file.jar". 启动配置用于使用预定义的“ Main”类(这是“ Runnable”部分...)通过“ java -jar file.jar”执行此JAR。
    If you don't plan to - it won't matter. 如果您不打算-没关系。
  4. (Optional) You can also "Save as ANT script" which, well..., generates XML ant script as well. (可选)您还可以“另存为ANT脚本”,它也可以生成XML ant脚本。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM