Java 如何在 Eclipse 和 Android Studio 中设置类路径

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

How to set the class path in Eclipse and Android Studio

javaeclipseandroid-studioclasspath

提问by Sweeper

I've heard that you can use classpathto use classes in other libraries. I googled about this and all results tell me to use the command line to compile the program and specify a classpath. But who would use command line to compile java programs nowadays?

我听说您可以使用classpath其他库中的类。我搜索了这个,所有结果都告诉我使用命令行来编译程序并指定一个类路径。但是现在谁会用命令行来编译java程序呢?

I am using eclipse and Android Studio. I mean they are IDEs so they surely can set the classpath very easily, right?

我正在使用 Eclipse 和 Android Studio。我的意思是它们是 IDE,所以它们肯定可以很容易地设置类路径,对吗?

Also, I want to know the word "library" in this context is just a jar file , right?

另外,我想知道在这种情况下“库”这个词只是一个 jar 文件,对吗?

采纳答案by Sumit Singh

In Eclipse:

在日食中:

Right-Clickon the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARsand give the Jar.

右键单击Project → Build Path → Configure Build Path。在库选项卡下,单击Add Jars or Add External JARs并提供 Jar。

Image from link
enter image description here

图片来自链接
在此处输入图片说明

Android Studio:from Android Studio: Add jar as library?

Android Studio:来自Android Studio:将 jar 添加为库?

  1. Right click on the module in the left hand panel and choose Open Module Settings. enter image description here
  2. On the left panel of the dialog, choose Libraries.
  3. Click the +sign above the panel second from the left -> Javaenter image description here
  4. Select your local jar and add it to the project.
  1. 右键单击左侧面板中的模块并选择Open Module Settings在此处输入图片说明
  2. 在对话框的左侧面板上,选择Libraries
  3. 单击+第二个面板上方的标志left -> Java在此处输入图片说明
  4. 选择您的本地 jar 并将其添加到项目中。

回答by Raghav Simlote

In eclipse, Right Click on Project -> Properties -> Java Build Path -> Add Class Folder or Simply copy your jar file to the libs folder in your project. Right click on jar file, Select "Build Path" then click "Add to build path".

在 eclipse 中,右键单击 Project -> Properties -> Java Build Path -> Add Class Folder 或简单地将 jar 文件复制到项目中的 libs 文件夹。右键单击 jar 文件,选择“构建路径”,然后单击“添加到构建路径”。

In Android Studio, Simply copy your jar file to the libs folder in your project. Right Click on Project -> Module Settings Select your project from the left and click on "+" sign at the bottom and select "jars or directories". Go to your project's libs folder and select the jar file which you have copied in that folder in step 1 and press OK Just make sure to check the box and then press "Apply" or "Ok" button to finish the process.

在 Android Studio 中,只需将 jar 文件复制到项目中的 libs 文件夹即可。右键单击项目 -> 模块设置 从左侧选择您的项目,然后单击底部的“+”号并选择“jars 或目录”。转到您项目的 libs 文件夹并选择您在步骤 1 中复制到该文件夹​​中的 jar 文件,然后按 OK 只需确保选中该框,然后按“应用”或“确定”按钮完成该过程。