java - 在 Linux 上运行程序时出现错误。在 Windows 上它工作正常

标签 java linux classpath

我做了一个java程序。我用的是eclipse,它是一个maven项目。现在,当我从 Windows 命令提示符运行该程序时,它运行良好。这里我如何从 Windows 命令提示符运行它

D:\Personal Work\eclipse 32 Bit\workspace\....\target\classes>
java -cp ".;..\dependency-jars\*"  com/softech/ls360/integration/BatchImport vintners

工作正常。我的依赖 jar 文件夹包含这些 jar 文件

dependency-jars

现在当我从 Linux 运行相同的程序时。这是我的运行方式

root@Basit:/home/test/script/classes# java -cp .;../dependency-jars/*;  com.s
oftech.ls360.integration.BatchImport vintners

然后我收到错误

....
-javaagent:<jarpath>[=<options>]
              load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
              show splash screen with specified image
../dependency-jars/commons-collections-3.2.1.jar: line 1: PK??: command not found
../dependency-jars/commons-collections-3.2.1.jar: line 2:
../dependency-jars/commons-collections-3.2.1.jar: line 2: ?8: command not found
../dependency-jars/commons-collections-3.2.1.jar: line 3: syntax error near unex
pected token `)'
../dependency-jars/commons-collections-3.2.1.jar: line 3: ?     ¶META-INF/MANIFE
ST.MF?VKo
     _¦?z?  ?%+v?N??!ö!P@
                         (
                          _?o.5?$
com.softech.ls360.integration.BatchImport: command not found

为什么我会收到这些错误。我怎样才能在Linux上运行它?请帮忙

谢谢

最佳答案

在 Linux 环境下,您需要在类路径中使用 : 而不是 ; 。假设您已正确放置 jar ,则只需更改此即可:

java -cp .;../dependency-jars/*;  com.s
oftech.ls360.integration.BatchImport vintners

java -cp .:../dependency-jars/*:  com.s
oftech.ls360.integration.BatchImport vintners

应该可以

在此处了解有关设置类路径的更多信息:http://docs.oracle.com/javase/tutorial/essential/environment/paths.html

关于java - 在 Linux 上运行程序时出现错误。在 Windows 上它工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18252735/

相关文章:

java - 如何访问 VariableDeclarationStatement 中的 MethodInvocation

java - 在 Android 所有 Activity 上设置标签栏底部

linux - 如何在空行上拆分带有文本内容的变量

linux - Linux 中核心空闲或核心离线有什么区别?

linux - 运行 cmp 'A' 的段错误,%al‽

java - 为什么在 mvn :assembly 构建的批处理中使用 args4j 时出现 java.lang.NoClassDefFoundError

java - Mockito:如何 stub getter setter

java - 在 Java 中使用什么数据结构来添加对象和使用 subList

eclipse : Project properties don't show Build Path

Java ant jar 任务和类路径问题