Java 如何在 Eclipse 中使用 .jar 文件的内容作为项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19856667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:45:21  来源:igfitidea点击:

How to use the content of a .jar file as project in Eclipse?

javajar

提问by lisa

i received a .jar file and want to use the content of the file as an Eclipse projectNOT

我收到了一个 .jar 文件并想使用该文件的内容as an Eclipse projectNOT

in an Eclipse project

I have tried to extract the .jar file, but eclipse doesn't reconize it as java project. The Jar file contains .class and .java files.

我试图提取 .jar 文件,但 eclipse 没有将其重新定义为 java 项目。Jar 文件包含 .class 和 .java 文件。

I already tried this way:

我已经尝试过这种方式:

1-extract the JAR-file
2-create an new project in eclipse
3-right click on that project
4-import
5-file system

But i didn't work!

但我没有工作!

How can i proceed?

我该如何继续?

Thank you!

谢谢!

采纳答案by Philipp Sander

if you want to modify the code, this works if the JAR contains the source-files:

如果您想修改代码,如果 JAR 包含源文件,这将起作用:

  1. extract the JAR-file
  2. create an new project in eclipse
  3. show the project (+)
  4. right click on the "src" folder
  5. import
  6. file system
  7. choose the folder you want to import
  8. check it in the left panel
  1. 提取 JAR 文件
  2. 在eclipse中创建一个新项目
  3. 显示项目 (+)
  4. 右键单击“src”文件夹
  5. 进口
  6. 文件系统
  7. 选择要导入的文件夹
  8. 在左侧面板中检查它

if you just want to use the classes in the JAR-file

如果您只想使用 JAR 文件中的类

  1. rigth click on the project
  2. build path.
  3. libraries and click on Add external JARS.
  1. 右键单击项目
  2. 构建路径。
  3. 库,然后单击添加外部 JARS。

if you want to modify the code of the JAR but it does not contain the source files, you need to decompile the class-files.

如果你想修改 JAR 的代码但它不包含源文件,你需要反编译类文件。

回答by Sandeep

you can attach that jar by following steps-

您可以按照以下步骤附加该罐子-

  1. Rigth click on project go to properties

  2. Then choose java build path.

  3. Then libraries and click on Add external JARS.
  1. 右键单击项目转到属性

  2. 然后选择java构建路径。

  3. 然后是库并单击添加外部 JARS。

回答by TrueDub

Do you need the source code, or just to use that jar as part of another project? If the former, you need the actual source code, as the jar is compiled, if the latter, simply add it to the build path, by right-clicking the project, selecting Build Path --> Add External Archives

您是否需要源代码,或者只是将该 jar 用作另一个项目的一部分?如果是前者,您需要实际的源代码,因为 jar 是编译好的,如果是后者,只需将其添加到构建路径中,通过右键单击项目,选择构建路径 --> 添加外部档案

回答by mikehoncho

If you need the code, Simply:

如果您需要代码,只需:

1) Right click on your existing src folder (or a new folder you can create if you want)

1) 右键单击​​您现有的 src 文件夹(或您可以根据需要创建的新文件夹)

2) Select "Import"

2)选择“导入”

3) Under "General" select "Archive File"

3)在“常规”下选择“存档文件”

4) Browse for your jar file. You will then be able to see all of the jar's contents.

4) 浏览您的 jar 文件。然后,您将能够看到 jar 的所有内容。

5) Click finish and you are done.

5)点击完成,你就完成了。