简体   繁体   English

如何将开源API代码添加到eclipse项目?

[英]how do I add open source API code to an eclipse project?

I have to write a java application which I'm putting together using eclipse and it relies on open source code. 我必须编写一个使用eclipse组合在一起的Java应用程序,它依赖于开源代码。 This application needs to be self-contained, meaning that I'm supposed to create a jar file that has no external dependencies. 该应用程序必须是独立的,这意味着我应该创建一个没有外部依赖关系的jar文件。

I can use the open source code when I reference the jar files in the project's build path, but the idea is to have the actual source code as part of the eclipse project, side-by-side with my code. 当我在项目的构建路径中引用jar文件时,可以使用开源代码,但其想法是将实际的源代码作为eclipse项目的一部分,与我的代码并排放置。

The source code can be found here: http://hc.apache.org/ , but when I import an existing file system into my project I can't quite get things to work. 可以在以下位置找到源代码: http : //hc.apache.org/ ,但是当我将现有文件系统导入到我的项目中时,我无法完全正常工作。 The packages end up with the wrong names, breaking references, and I can't do anything. 这些软件包的名称以错误的名称结尾,破坏了引用,并且我什么也做不了。 Notice that the folder containing the source code has this structure: 请注意,包含源代码的文件夹具有以下结构:

 httpcomponents-client-4.2.3\
    src\
    httpmime\
    httpclient-osgi
    httpclient-contrib
    httpclient-cache
    httpclient-benchmark
    httpclient
    fluent-hc

each of those subfolders has src/main/java/org/apache subfolders. 这些子文件夹中的每一个都有src / main / java / org / apache子文件夹。

Can someone please explain how to do this? 有人可以解释一下该怎么做吗? Am I supposed to import everything one java file at a time? 我是否应该一次将所有内容导入一个Java文件?

Use a tool like OneJar , FatJar , JarJar , etc. to create a single-jar application. 使用诸如OneJarFatJarJarJar等工具创建单个jar应用程序。

As Charlie mentioned, the Maven Shade plugin is another choice, particularly if you're already using Maven. 正如Charlie提到的, Maven Shade插件是另一种选择,特别是如果您已经在使用Maven。 If you're not, consider it or another transitive dependency management tool. 如果不是,请考虑使用它或其他可传递依赖项管理工具。

Some tool should be used, IMO, and it's more important the more dependencies you have. 应该使用某些工具IMO,并且您拥有的依赖项越多越重要。

Alternatively you could use a jar class loader and include the jar file in your artifact. 或者,您可以使用jar类加载器 ,并将jar文件包含在工件中。

I would most definitely not include the source of dependencies in your own project. 我绝对不会在您自己的项目中包括依赖项的来源

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

相关问题 如何在Eclipse中将源代码附加到项目的库中? - How do I attach source code into a project's library in Eclipse? 在Eclipse中,如何将“打开类型”快捷方式限制为仅显示当前项目中的源文件 - In Eclipse, how do I limit the Open Type shortcut to only show source files in my current project 如何将源代码导入eclipse - How do i import a source code into eclipse Eclipse,Java项目-如何添加源文件夹,其中文件夹名称是软件包名称的一部分? - Eclipse, Java project - How do I add a source folder where the folder name is part of the package name? 如何在Eclipse ADT中打开Android源代码 - How to open Android source code in Eclipse ADT 如何在Eclipse for OSX中打开并运行此Java项目 - How do I open and run this Java project in Eclipse for OSX 如何将工作服集成到开源项目中? - How do I Integrate Coveralls to An Open-Source Project? 如何在Eclipse中添加开放源代码文件,以便`Ctrl + Shift + R`显示源代码文件? - How to add Open Sources Code Files in Eclipse, so that `Ctrl+Shift+R` shows the Source Code Files? 如何在 Eclipse 中查看 JRE 的源代码? - How do I view JRE's source code in Eclipse? 如何将现有的eclipse java项目添加到git - How do I add existing eclipse java project to git
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM