在编译Java类并从命令控制台运行Java文件时,如何包括Java jar文件? [英] How will I include a Java jar file when compiling a Java class and running the Java file from the command console?

查看:380
本文介绍了在编译Java类并从命令控制台运行Java文件时,如何包括Java jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的Java文件与postgresql数据库交互,
所以我已经下载了驱动程序和在我的文件中我导入 org.postgresql.Driver

I have a small Java file interacting with a postgresql database, so I've downloaded the drivers and in my file I import org.postgresql.Driver.

在命令控制台中输入 javac Myfilename.java ;
然后它编译我运行 java Myfilename ,它会抛出一个错误,说它找不到 org.postgresql.Driver 文件。

In the command console I type javac Myfilename.java ; then it compiles I run java Myfilename and it throws an error saying it can not find the org.postgresql.Driver files.

那么,当我运行该文件或者当我编译该文件时,如何导入jar不知道什么时候应该导入?

So how do I import the jar when I run the file or when I compile the file not sure when the import should take place?

推荐答案

编译:

javac -cp ".:postresql.jar" -d . MyFileName.java

执行:

java -cp ".:postresql.jar" MyFileName

这篇关于在编译Java类并从命令控制台运行Java文件时,如何包括Java jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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