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

时间:2023-01-13 22:06:18

This question already has an answer here:

这个问题在这里已有答案:

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" code to 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中添加此项目并使其快速编译和运行?

4 个解决方案

#1


19  

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

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

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

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

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

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

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

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

  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)

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

  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.

    回到Eclipse,选择在步骤1中创建的项目,然后点击F5键(这将刷新Eclipse的文件夹树视图和实际内容。

  7. The content of the /src folder 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 files from the project classpath.

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

  8. Finally, open the /lib folder in Eclipse, right click on each required jar file and choose Build Path->Add to build path.

    最后,打开Eclipse中的/ lib文件夹,右键单击每个必需的jar文件,然后选择Build Path-> Add to build path。

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项目。

#2


13  

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

我想你必须通过file-> import wizard导入项目:

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设计师请不要简单地复杂化)。

#3


11  

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. 打开Eclipse并通过指定空目录来创建新的Workspace。

  3. Make sure you're in the Java perspective by selecting Window -> Open Perspective ..., select Other... and then Java
  4. 通过选择Window - > Open Perspective ...确保您处于Java透视图中,选择Other ...然后选择Java

  5. Right click anywhere in the Package Explorer pane and select New -> Java Project
  6. 右键单击Package Explorer窗格中的任意位置,然后选择New - > Java Project

  7. In the dialog that opens give the project a name and then click the option that says "Crate project from existing sources."
  8. 在打开的对话框中为项目命名,然后单击“从现有源包装项目”选项。

  9. 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"
  10. 在步骤4中选择的选项下方的文本框中,指向您签出项目的根目录。这应该是包含“com”的目录

  11. 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.
  12. 单击完成。对于此特定项目,您不需要为类路径执行任何其他设置,因为它仅依赖于属于Java SE API的类。

#4


6  

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'

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

#1


19  

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

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

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

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

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

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

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

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

  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)

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

  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.

    回到Eclipse,选择在步骤1中创建的项目,然后点击F5键(这将刷新Eclipse的文件夹树视图和实际内容。

  7. The content of the /src folder 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 files from the project classpath.

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

  8. Finally, open the /lib folder in Eclipse, right click on each required jar file and choose Build Path->Add to build path.

    最后,打开Eclipse中的/ lib文件夹,右键单击每个必需的jar文件,然后选择Build Path-> Add to build path。

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项目。

#2


13  

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

我想你必须通过file-> import wizard导入项目:

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设计师请不要简单地复杂化)。

#3


11  

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. 打开Eclipse并通过指定空目录来创建新的Workspace。

  3. Make sure you're in the Java perspective by selecting Window -> Open Perspective ..., select Other... and then Java
  4. 通过选择Window - > Open Perspective ...确保您处于Java透视图中,选择Other ...然后选择Java

  5. Right click anywhere in the Package Explorer pane and select New -> Java Project
  6. 右键单击Package Explorer窗格中的任意位置,然后选择New - > Java Project

  7. In the dialog that opens give the project a name and then click the option that says "Crate project from existing sources."
  8. 在打开的对话框中为项目命名,然后单击“从现有源包装项目”选项。

  9. 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"
  10. 在步骤4中选择的选项下方的文本框中,指向您签出项目的根目录。这应该是包含“com”的目录

  11. 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.
  12. 单击完成。对于此特定项目,您不需要为类路径执行任何其他设置,因为它仅依赖于属于Java SE API的类。

#4


6  

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'

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