用Java导入自定义库 [英] Import custom libraries in Java

查看:116
本文介绍了用Java导入自定义库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在项目中导入Java类。我需要导入的类是一个JAR文件,其中
绝对路径〜/ Documents / mylib / stdlib.jar

I need to import a Java class in my project. The class I need to import is in a JAR file with absolute path ~/Documents/mylib/stdlib.jar

现在在我的源文件(Test.java)中我正在使用

Now in my source file (Test.java) I am using

import stdlib。*;

我用
编译 javac -classpath~ / Documents / mylib / stdlib.jar Test.java

它显示stdlib不存在的错误。

And it is showing the error that stdlib does not exist.

我的import语句是否正确或者类路径有什么问题吗?
这个import语句不应该导入JAR文件中的所有类吗?

Is my import statement correct or is there anything wrong with classpath? Shouldn't this import statement import all the classes present in the JAR file?

我没有使用任何IDE而我的操作系统是Linux。

I am not using any IDE and my OS is Linux.

推荐答案

import语句从jar文件导入类,而不是jar文件本身。

The import statement imports classes from the jar file, not the jar file itself.

表单的import语句:

An import statement of the form:

  import stdlib.*;

将导入 stdlib中的所有类。

will import all the classes in the package stdlib.

Oracle在导入时提供本教程

Oracle provides this tutorial on import.

编辑:看起来您正在使用stdlib.jar Java编程简介。此jar文件中的类没有包。您不需要在默认包中导入类,因为您的类也在默认包中。

It looks like you're using the stdlib.jar for An introduction to programming in Java. The classes in this jar file have no packages. You don't need to import classes in the default package, since your class is also in the default package.

这篇关于用Java导入自定义库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆