问题描述
我正在关注本教程制作与数据库交互的程序.我被困在运行它的最后一步.给定的例子是C:\test>java -cp c:\test\postgresql-8.3-603.jdbc4.jar;c:\test JDBCExample
I am following this tutorial to make a program that interacts with the database. I am stuck at the last step where I run it. The given example isC:\test>java -cp c:\test\postgresql-8.3-603.jdbc4.jar;c:\test JDBCExample
我的主目录中同时具有JDBC的.class文件和.jar.我尝试过
I have both the .class file and the .jar for the JDBC in my home directory. I tried
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB.class
,我得到无法提取二进制文件"
我试过了java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB
,我得到没有这样的文件或目录"
我试过了java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF QueryDB
,我得到"JohnF是目录"
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB.class
and I get "cannot exectue binary file"
I triedjava -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB
and I get "no such file or directory"
I triedjava -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF QueryDB
and I get "JohnF is a directory"
我使用chmod
将文件权限设置为777
.我该如何运行它?
I used chmod
to set the file permissions to 777
. How do I get this to run?
推荐答案
您正在使用分号作为类路径分隔符-这在Linux上不起作用.尝试替换;"在类路径中使用:",它应该可以工作.
You are using semicolon as classpath separator - this will not work on Linux.Try replacing ";" with ":" in classpath and it should work.
编辑:此处发生的情况的说明. 在Linux中,;"是命令分隔符.您的行
explanation of what is happening here. In Linux, ";" is command separator. Your line of
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF QueryDB
确实扩展为2个一对一执行:
is really expanded into 2 executed one by one:
java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar
/home/JohnF QueryDB
第一个不执行任何操作并成功退出.第二个尝试将/home/JohnF
作为可执行文件调用,这实际上不是可执行文件,而是目录!
First one does nothing and successfully quits.Second tries to invoke /home/JohnF
as executable, and this is really not an executable, but a directory!
这篇关于从Linux命令行运行Java程序需要一个附加文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!