如何将预先存在的 Java 项目导入 Eclipse 并启动并运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/142863/
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-11 08:51:47  来源:igfitidea点击:

How do I import a pre-existing Java project into Eclipse and get up and running?

javaeclipse

提问by JR Lawhorne

Comment on Duplicate Reference: Why would this be marked duplicate when it was asked years prior to the question referenced as a duplicate? I also believe the question, detail, and response is much better than the referenced question.

对重复引用的评论:为什么在被引用为重复的问题之前几年被问到时,这会被标记为重复?我也相信问题、细节和回应比引用的问题要好得多。

I've been a C++ programmer for quite a while but I'm new to Java and new to Eclipse. I want to use the touch graph "Graph Layout" codeto visualize some data I'm working with.

我做 C++ 程序员已经有一段时间了,但我是 Java 新手,也是 Eclipse 新手。我想使用触摸图“图形布局”代码来可视化我正在处理的一些数据。

This code is organized like this:

这段代码是这样组织的:

./com
./com/touchgraph
./com/touchgraph/graphlayout
./com/touchgraph/graphlayout/Edge.java
./com/touchgraph/graphlayout/GLPanel.java
./com/touchgraph/graphlayout/graphelements
./com/touchgraph/graphlayout/graphelements/GESUtils.java
./com/touchgraph/graphlayout/graphelements/GraphEltSet.java
./com/touchgraph/graphlayout/graphelements/ImmutableGraphEltSet.java
./com/touchgraph/graphlayout/graphelements/Locality.java
./com/touchgraph/graphlayout/graphelements/TGForEachEdge.java
./com/touchgraph/graphlayout/graphelements/TGForEachNode.java
./com/touchgraph/graphlayout/graphelements/TGForEachNodePair.java
./com/touchgraph/graphlayout/graphelements/TGNodeQueue.java
./com/touchgraph/graphlayout/graphelements/VisibleLocality.java
./com/touchgraph/graphlayout/GraphLayoutApplet.java
./com/touchgraph/graphlayout/GraphListener.java
./com/touchgraph/graphlayout/interaction
./com/touchgraph/graphlayout/interaction/DragAddUI.java
./com/touchgraph/graphlayout/interaction/DragMultiselectUI.java
./com/touchgraph/graphlayout/interaction/DragNodeUI.java
./com/touchgraph/graphlayout/interaction/GLEditUI.java
./com/touchgraph/graphlayout/interaction/GLNavigateUI.java
./com/touchgraph/graphlayout/interaction/HVRotateDragUI.java
./com/touchgraph/graphlayout/interaction/HVScroll.java
./com/touchgraph/graphlayout/interaction/HyperScroll.java
./com/touchgraph/graphlayout/interaction/LocalityScroll.java
./com/touchgraph/graphlayout/interaction/RotateScroll.java
./com/touchgraph/graphlayout/interaction/TGAbstractClickUI.java
./com/touchgraph/graphlayout/interaction/TGAbstractDragUI.java
./com/touchgraph/graphlayout/interaction/TGAbstractMouseMotionUI.java
./com/touchgraph/graphlayout/interaction/TGAbstractMousePausedUI.java
./com/touchgraph/graphlayout/interaction/TGSelfDeactivatingUI.java
./com/touchgraph/graphlayout/interaction/TGUIManager.java
./com/touchgraph/graphlayout/interaction/TGUserInterface.java
./com/touchgraph/graphlayout/interaction/ZoomScroll.java
./com/touchgraph/graphlayout/LocalityUtils.java
./com/touchgraph/graphlayout/Node.java
./com/touchgraph/graphlayout/TGAbstractLens.java
./com/touchgraph/graphlayout/TGException.java
./com/touchgraph/graphlayout/TGLayout.java
./com/touchgraph/graphlayout/TGLensSet.java
./com/touchgraph/graphlayout/TGPaintListener.java
./com/touchgraph/graphlayout/TGPanel.java
./com/touchgraph/graphlayout/TGPoint2D.java
./com/touchgraph/graphlayout/TGScrollPane.java
./TG-APACHE-LICENSE.txt
./TGGL ReleaseNotes.txt
./TGGraphLayout.html
./TGGraphLayout.jar

How do I add this project in Eclipse and get it compiling and running quickly?

如何在 Eclipse 中添加此项目并使其快速编译和运行?

采纳答案by Kevin Day

  1. Create a new Java project in Eclipse. This will create a src folder (to contain your source files).

  2. Also create a lib folder (the name isn't that important, but it follows standard conventions).

  3. Copy the ./com/*folders into the /srcfolder (you can just do this using the OS, no need to do any fancy importing or anything from the Eclipse GUI).

  4. Copy any dependencies (jarfiles that your project itself depends on) into /lib(note that this should NOTinclude the TGGL jar- thanks to commenter Mike Deck for pointing out my misinterpretation of the OPs post!)

  5. Copy the other TGGL stuff into the root project folder (or some other folder dedicated to licenses that you need to distribute in your final app)

  6. Back in Eclipse, select the project you created in step 1, then hit the F5 key (this refreshes Eclipse's view of the folder tree with the actual contents.

  7. The content of the /srcfolder will get compiled automatically (with class files placed in the /bin file that Eclipse generated for you when you created the project). If you have dependencies(which you don't in your current project, but I'll include this here for completeness), the compile will fail initially because you are missing the dependency jar filesfrom the project classpath.

  8. Finally, open the /libfolder in Eclipse, right clickon each required jar fileand choose Build Path->Addto build path.

  1. 在 Eclipse 中创建一个新的 Java 项目。这将创建一个 src 文件夹(以包含您的源文件)。

  2. 还要创建一个 lib 文件夹(名称并不重要,但它遵循标准约定)。

  3. ./com/*文件夹复制到文件/src夹中(您可以使用操作系统执行此操作,无需从 Eclipse GUI 执行任何花哨的导入或任何操作)。

  4. 将任何依赖项(jar您的项目本身所依赖的文件)复制到/lib(请注意,这不应包括TGGL jar-感谢评论者 Mike Deck 指出我对 OP 帖子的误解!

  5. 将其他 TGGL 内容复制到根项目文件夹(或其他一些专用于您需要在最终应用程序中分发的许可证的文件夹)

  6. 返回 Eclipse,选择您在步骤 1 中创建的项目,然后按 F5 键(这将使用实际内容刷新 Eclipse 的文件夹树视图。

  7. /src文件夹的内容将被自动编译(类文件放置在 Eclipse 在您创建项目时为您生成的 /bin 文件中)。 如果您有依赖项(您当前的项目中没有,但为了完整起见,我将在此处包括在内),编译最初将失败,因为您缺少jar files项目类路径中的依赖项。

  8. 最后,/lib在 Eclipse 中打开文件夹,right click在每个需要的地方jar file并选择Build Path->Add构建路径。

That will add that particular jar to the classpath for the project. Eclipse will detect the change and automatically compile the classes that failed earlier, and you should now have an Eclipse project with your app in it.

这会将该特定 jar 添加到项目的类路径中。Eclipse 将检测更改并自动编译之前失败的类,您现在应该有一个包含您的应用程序的 Eclipse 项目。

回答by Mike Deck

This assumes Eclipse and an appropriate JDK are installed on your system

这假设您的系统上安装了 Eclipse 和适当的 JDK

  1. Open Eclipse and create a new Workspace by specifying an empty directory.
  2. Make sure you're in the Java perspective by selecting Window -> Open Perspective ..., select Other... and then Java
  3. Right click anywhere in the Package Explorer pane and select New -> Java Project
  4. In the dialog that opens give the project a name and then click the option that says "Crate project from existing sources."
  5. In the text box below the option you selected in Step 4 point to the root directory where you checked out the project. This should be the directory that contains "com"
  6. Click Finish. For this particular project you don't need to do any additional setup for your classpath since it only depends on classes that are part of the Java SE API.
  1. 打开 Eclipse 并通过指定一个空目录来创建一个新的工作区。
  2. 通过选择 Window -> Open Perspective ...,选择 Other...,然后选择 Java,确保您处于 Java 透视图中
  3. 右键单击 Package Explorer 窗格中的任意位置并选择 New -> Java Project
  4. 在打开的对话框中,为项目命名,然后单击“从现有源创建项目”选项。
  5. 在您在步骤 4 中选择的选项下方的文本框中,指向您检出项目的根目录。这应该是包含“com”的目录
  6. 单击完成。对于这个特定项目,您不需要为类路径做任何额外的设置,因为它只依赖于属于 Java SE API 的类。

回答by Thotman

I think you'll have to import the project via the file->import wizard:

我认为您必须通过文件-> 导入向导导入项目:

http://www.coderanch.com/t/419556/vc/Open-existing-project-Eclipse

http://www.coderanch.com/t/419556/vc/Open-existing-project-Eclipse

It's not the last step, but it will start you on your way.

这不是最后一步,但它会让你开始上路。

I also feel your pain - there is really no excuse for making it so difficult to do a simple thing like opening an existing project. I truly hope that the Eclipse designers focus on making the IDE simpler to use (tho I applaud their efforts at trying different approaches - but please, Eclipse designers, if you are listening, never complicate something simple).

我也感受到你的痛苦——真的没有理由让打开一个现有项目这样简单的事情变得如此困难。我真的希望 Eclipse 设计人员专注于使 IDE 更易于使用(虽然我赞赏他们尝试不同方法的努力 - 但请 Eclipse 设计人员,如果您正在倾听,永远不要将简单的事情复杂化)。

回答by Hrqls

In the menu go to : - File - Import - as the filter select 'Existing Projects into Workspace' - click next - browse to the project directory at 'select root directory' - click on 'finish'

在菜单中转到: - 文件 - 导入 - 作为过滤器选择“现有项目到工作区” - 单击下一步 - 在“选择根目录”处浏览到项目目录 - 单击“完成”