简体   繁体   English

将项目(jar)导入Eclipse

[英]Import project (jar) into Eclipse

I got a .jar file which I need to import into Eclipse. 我有一个.jar文件,我需要导入Eclipse。 However, I don't want to have the jar as a referenced library. 但是,我不希望将jar作为引用库。 I need the .jar to be included like a "normal" project, with packages(!) and .java files. 我需要将.jar包含为“普通”项目,包含(!)和.java文件。

I tried to do the following: New Java project -> Import -> General -> Archive File. 我尝试执行以下操作:新Java项目 - >导入 - >常规 - >存档文件。 In this case, when I place this jar also as a referenced library, it is imported but with .class files. 在这种情况下,当我将此jar也作为引用库放置时,它将被导入但使用.class文件。

New Java Project -> Import -> General -> File System. 新Java项目 - >导入 - >常规 - >文件系统。 Imports the .java files, but the packages are lost and are normal folders. 导入.java文件,但包丢失并且是普通文件夹。 Also, the files are somehow strange, because the "j" in the icon looks differently, and errors are not noticed (no underlining) 此外,文件有点奇怪,因为图标中的“j”看起来不同,并且没有注意到错误(没有下划线)

Importing "Existing Projects into Workspace" doesn't work at all, it says that there is no project. 将“现有项目导入工作区”根本不起作用,它说没有项目。 I also tried to import the jar as a zip after extracting it, this gives me the -java files, but it destroys the packages. 我也尝试在解压缩后将jar作为zip导入,这给了我-java文件,但它会破坏包。

Does anyone know how to import this correctly? 有谁知道如何正确导入?

I have managed it this way: New Java Project -> Java settings -> Source -> Link source (Source folder). 我用这种方式管理它:New Java Project - > Java settings - > Source - > Link source(Source folder)。 There I added my decompiled jar and it was imported correctly :) 在那里,我添加了我的反编译jar并正确导入:)

You can also create a new Java Project and then do File -> Import -> General -> Archive File. 您还可以创建一个新的Java项目,然后执行文件 - >导入 - >常规 - >存档文件。 This will save you a step of unzipping your jar and adding as a linked source folder. 这将为您节省解压缩jar并添加为链接源文件夹的步骤。

You cannot import a jar that way, unless it has the source code packed in the jar. 你不能以这种方式导入jar,除非它在jar中包含源代码。 If you really need the source code, you'll have to find an archive somewhere. 如果您确实需要源代码,则必须在某处找到存档。 But of course, not everyone is willing to share his source... 但当然,不是每个人都愿意分享他的消息来源......

I tried the below and it worked. 我尝试了下面的工作。

  1. Create a New Java Project 创建一个新的Java项目
  2. Goto File > Import > General > Archive File 转到File > Import > General > Archive File
  3. Select the required Archive file( .jar in this case) from your local system. 从本地系统中选择所需的存档文件(在本例中为.jar )。
  4. Select the project you created in Step 1 and click Ok 选择您在步骤1中创建的项目,然后单击“ Ok

This will save you a step of unzipping your jar but if there are .class files, eclipse won't convert them to .java files. 这将为您节省解压缩jar的步骤,但如果有.class文件,eclipse将不会将它们转换为.java文件。 This has to be done seperately. 这必须单独完成。

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

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