在linux上运行程序时出错。 在Windows上,它工作正常

我做了一个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文件

依赖关系的罐子

现在,当我从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环境下的classpath中。 假设你有正确的罐子放置,然后简单地改变这个:

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

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

应该管用

详细了解如何在此设置classpath: http : //docs.oracle.com/javase/tutorial/essential/environment/paths.html

分号让Bash调用没有classpath的java命令,然后试图直接执行每个jar,寻找一个没有的shebang。 这导致JAR头被打印作为错误的一部分。

使用:在Linux上分开jar而不是分号。

您需要进行两项更改:

  1. 首先,类路径分隔符是':'而不是';' 在Linux上
  2. 其次,你需要用反斜线('\')来转义通配符,否则shell将会扩展它并将其搞乱。 您希望Java能够看到“*”字符并将其自身展开。 Windows shell不会在命令行上扩展通配符,所以这不是问题。

所以,一起,你会想要使用类似的东西

 java -cp .:../dependency-jars/\*: com.softech.ls360.integration.BatchImport vintners 

你应该使用:而不是; 作为类路径文件的一个扩展器。