外部JAR文件创建的Eclipse JAR导出设置(用于导入到另一个项目)

时间:2013-10-31 14:38:42

标签: java eclipse jar

我有一个项目,我想添加一个外部JAR文件。所需的外部JAR文件有一个带源的漂亮的Github页面,但没有预编译的JAR文件。

这是我到目前为止完成的步骤:

1. I have downloaded the source in a zip. (its Twinkle from SwingFx.ch in case you're interested)
2. I have extracted the zip file to my workspace.
3. I have created a new project with the same name as the extracted folder from the zip file. (project loads the source successfully)
4. I select the export option from the File menu and selected the 'JAR file' option and clicked next.

注意:我必须在上面的Twinkle项目中添加一个外部库才能成功构建(如果这会对设置产生影响)。

在JAR文件规范页面上有多个可用的复选框选项(见下文):

Export generated class file and resources
Export all output folder for checked projects
Export Java source files and resources
Export refactorings for checked projects
Compress the contents of the JAR file
Add directory entries

我不确定应该选择哪个,如果它对项目的行为产生影响,我会将(即将出版的)导出的JAR文件添加到。我通过使用默认设置导出来测试它。这工作正常..但是,我现在不知道我是否应该选择不同的设置,以防我不知道任何原因。我不确定当我打算将JAR文件作为外部JAR文件添加到另一个项目时是否应该选择特定的设置。

请赐教!

1 个答案:

答案 0 :(得分:2)

这是一个使用Maven的传统Java库。使用Maven进行构建应该相当容易,如果已经安装了Maven和git,那么构建它应该更好更快。

让我们考虑一下你没有把源文件下载为zip,但是采用github方法,你可以使用git下载源代码。

  1. 如果你没有git,download its latest version并安装它。
  2. 如果您没有Maven,download its latest version并安装它。
  3. 安装Maven和git后,请确保在环境PATH变量中配置了Maven和git二进制文件。如果未设置,您将在Windows平台和Maven二进制文件中以这种方式设置它(使用默认安装路径):

    设置PATH =%PATH%; C:\ Program Files(x86)\ Apache \ maven-3.1.1 \ bin

  4. 在您选择的工作目录中创建和更改目录,我们将从现在开始引用%work_directory%。

  5. 运行以下命令:
  6. cd %work_directory% 
    git clone https://github.com/spreiter301/Core.git
    git clone https://github.com/spreiter301/Twinkle.git
    cd Core
    mvn clean install
    cd ../Twinkle
    mvn package
    

    6。检索新创建的'%work_directory%/ Twinkle / target'文件夹中的twinkle-1.0.0.jar文件。

    在这种情况下,有必要检索Core库,因为它是Twinkle项目的依赖项。通常,这不是必需的,因为从maven repository自动检索依赖关系。但在这种情况下,any Maven repository无法获得该依赖关系。因此,我们手动检索dependency from github,编译它并将其安装在本地缓存存储库中。然后我们可以将Twinkle project打包到JAR文件中。

    这应该这样做。如果您想在Maven上学习5分钟,there is a tutorial for this here。我强烈推荐它,你会经常在Java世界中遇到这种情况。 Maven是Java的标准构建工具,就像'make'代表C,'rake'代表Ruby,'sbt'代表Scala等等。祝其他人好运。

相关问题