简体   繁体   English

将外部.java文件添加到Eclipse构建路径

[英]Adding an external .java file to eclipse build path

I am taking a class in data structures, and they want us to use eclipse. 我正在学习数据结构课程,他们希望我们使用eclipse。 Unfortunately, the intro programming class I took used jgrasp, so that's what I am used to. 不幸的是,我参加的入门编程课使用的是jgrasp,所以这就是我的习惯。 While I REALLY like the way that eclipse works, I can't seem to figure out how to download the support files for my assignments into my project so that they are usable. 虽然我真的很喜欢eclipse的工作方式,但似乎无法弄清楚如何将作业的支持文件下载到我的项目中以便可以使用。 I have downloaded the support files, and put them into the same file as the class I am writing, but the downloaded files don't show up on eclipse, and when I try to implement the interfaces, they say that they don't exist. 我已经下载了支持文件,并将它们放在与我正在编写的类相同的文件中,但是下载的文件不会显示在eclipse上,并且当我尝试实现接口时,他们说它们不存在。 When I go through my computer, and look at the file with windows explorer, I can see all the files (both the ones that I downloaded and the ones that I wrote), but they don't show up in java, and when I try to use them, I get an error. 当我浏览计算机并使用Windows资源管理器查看文件时,我可以看到所有文件(我下载的文件和我编写的文件),但是它们并没有显示在Java中,当我尝试使用它们,我得到一个错误。 I'm sure this is a really easy fix, but if ANYBODY could help me, I would be extremely grateful. 我敢肯定,这确实很容易解决,但是如果ANYBODY可以帮助我,我将非常感激。

I have tried changing the build path, but I don't really understnad how to do that. 我已经尝试过更改构建路径,但是我并没有真正理解该怎么做。 The files I am trying to add are simple. 我要添加的文件很简单。 One is an interface and the other is a special exception class that my professor developed. 一个是接口,另一个是我的教授开发的特殊异常类。

According to your title, you are using a .java file (not .jar, which is different) in Eclipse. 根据您的标题,您正在Eclipse中使用.java文件(不是.jar,这是不同的)。

In that case, simply drag the .java file onto the Package Explorer pane in Eclipse and a popup should appear titled "File Operation" and ask how you want to import the files into Eclipse. 在这种情况下,只需将.java文件拖到Eclipse中的Package Explorer窗格中,然后会出现一个标题为“ File Operation”的弹出窗口,并询问您如何将文件导入Eclipse。

The options should be "Copy Files" and "Link to files". 选项应为“复制文件”和“链接到文件”。 Select "Copy Files" since that is easiest. 选择“复制文件”,因为这是最简单的。

After that, the Java code in the .java file becomes part of your project and the classes and interfaces defined in it can be called or implemented. 之后,.java文件中的Java代码将成为项目的一部分,并且可以调用或实现其中定义的类和接口。

Hope that helps! 希望有帮助!

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

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