简体   繁体   English

当我在 linux 控制台中执行我的“sh”文件时,Jar 文件不起作用

[英]Jar file dont work when i execute my "sh" File in linux consol

When i try to execute to execute this line当我尝试执行执行此行时

bash -x ExecutionAuto.bat

I get an error from my Lib folder saying that one of the jars isnt working properly.我从我的 Lib 文件夹中收到一条错误消息,指出其中一个 jars 工作不正常。

../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 1: $'PK\003\004': command not found
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 2: $'ؔ\220L': command not found
../Demo_Automatisation/lib/SparseBitSet-1.2.jar: line 8: syntax error near unexpected token `)'
��������0 6&»���2<��߽�{�i'���arseBitSet-1.2.jar: line 8: `��6)Ѐ*u)�����RP  �rN-p�đ�
                            �{�eB�M}i��Qa0�{}/�aHU�
'���xQXk)�Ћ.'?l3����A�I�|��0AİV���v�)s    ?���5N���V��v��hH�;"���~Gt  D��}|ȣ^�`�ܨ"r��d���}7��0t)y���{�W���
+ java org.testng.TestNG ../Demo_Automatisation/testng.xml
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG

I dont know if there is a probleme with the jar files since it works fine in Windows but in linux it doesnt work.我不知道 jar 文件是否有问题,因为它在 Windows 中工作正常,但在 linux 中不起作用。

This is my.sh file:这是 my.sh 文件:

export projectLocation=../Demo_Automatisation
cd $projectLocation
export CLASSPATH=$projectLocation/bin;$projectLocation/lib/*
java org.testng.TestNG $projectLocation/testng.xml

I just coppied what i found on the internet since i had a.bat file at first since i was using Windows does transferring from Windows to linux requieres that i do something to my jar files? I just coppied what i found on the internet since i had a.bat file at first since i was using Windows does transferring from Windows to linux requieres that i do something to my jar files?

The issue is that the ;问题是; in your classpath definition actually separates two commands so the $projectLocation/lib/* is interpreted as a new command, expands to the name of the jar file and the shell tries to execute the jar file as a shell script (which fails miserably). in your classpath definition actually separates two commands so the $projectLocation/lib/* is interpreted as a new command, expands to the name of the jar file and the shell tries to execute the jar file as a shell script (which fails miserably). On Linux the separator for classpaths is : and not ;在 Linux 上,类路径的分隔符是:而不是; (almost certainly for exactly this reason). (几乎可以肯定正是这个原因)。

In other words: instead of换句话说:而不是

export CLASSPATH=$projectLocation/bin;$projectLocation/lib/*

you need你需要

export CLASSPATH=$projectLocation/bin:$projectLocation/lib/*

As a bonus suggestion: the /* in the CLASSPATH should be interpreted by Java and not the shell, so it's better to actually quote the value:作为奖励建议: CLASSPATH中的/*应由 Java 而不是shell 解释,因此最好实际引用该值:

export CLASSPATH="$projectLocation/bin:$projectLocation/lib/*"

The projectLocation is a relative path which you reuse after changing the working directory. projectLocation是您在更改工作目录后重用的相对路径。 Try to use an absolute path, maybe it gets fixed that way.尝试使用绝对路径,也许它会以这种方式修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM