2015-01-02 19 views
1

(更新下面根據意見和答案)在Ubuntu上執行Java提供了亂碼輸出


我已經開發了在Windows上一些Java,我已經成功地執行它在該機器上。我第一次嘗試在Ubuntu上執行它。我安裝了OpenJDK-7-jre,並複製了jar和源代碼。

的罐子:

(djauth_venv)~/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build$ ls -la dependency_jars/ 
-rw-rw-r-- 1 jeffy jeffy 185140 Jun 12 2012 commons-io-2.4.jar 
-rw-rw-r-- 1 jeffy jeffy 18863 Dec 11 12:53 templatefeather-0.1.1.2.jar 
-rw-rw-r-- 1 jeffy jeffy 665303 Dec 11 12:52 xbnjava-0.1.5.jar 

當試圖與

java BuildPartFour -classpath /usr/lib/jvm/java-7-openjdk-i386/jre/lib/rt.jar;/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/commons-io-2.4.jar;/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar;/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar

這導致拒絕權限對每個罐子來執行它:

Exception in thread "main" java.lang.NoClassDefFoundError: com/github/xbn/io/PlainTextFileUtil 
     at BuildPartFour.main(BuildPartFour.java:14) 
Caused by: java.lang.ClassNotFoundException: com.github.xbn.io.PlainTextFileUtil 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
     ... 1 more 
-bash: /home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/commons-io-2.4.jar: Permission denied 
-bash: /home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: Permission denied 
-bash: /home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: Permission denied 

我已經將罐子更改爲可執行

(djauth_venv)[email protected]:~/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build$ chmod 774 dependency_jars/*.jar 
(djauth_venv)[email protected]:~/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build$ ls -la dependency_jars/    total 864 
-rwxrwxr-- 1 jeffy jeffy 185140 Jun 12 2012 commons-io-2.4.jar 
-rwxrwxr-- 1 jeffy jeffy 18863 Dec 11 12:53 templatefeather-0.1.1.2.jar 
-rwxrwxr-- 1 jeffy jeffy 665303 Dec 11 12:52 xbnjava-0.1.5.jar 

但現在,嘗試再次執行它時,我得到這個瘋狂的輸出:

Exception in thread "main" java.lang.NoClassDefFoundError: com/github/xbn/io/PlainTextFileUtil 
     at BuildPartFour.main(BuildPartFour.java:14) 
Caused by: java.lang.ClassNotFoundException: com.github.xbn.io.PlainTextFileUtil 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
     ... 1 more 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/commons-io-2.4.jar: line 1: $'PK\003\004': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/commons-io-2.4.jar: line 2: $'v\222\[email protected]': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/commons-io-2.4.jar: line 21: syntax error near unexpected token `)' 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/commons-io-2.4.jar: line 21: `▒Ғ▒^w▒ ▒▒W▒!▒▒ 
N▒ 
    g▒▒1^▒yKn▒K(▒"▒N▒▒▒ 
▒F/L*▒vTb6▒▒▒▒l4]▒▒▒hL▒F▒▒▒▒`▒l▒8m▒C▒▒▒▒▒▒▒u▒▒▒A▒*▒O▒▒▒▒6Jys▒▒C%▒▒݅Z▒ب▒&▒@▒▒▒9▒▒▒^▒"▒ID_▒▒▒▒$ +yr.,▒▒趒3▒a▒▒O▒▒▒eq▒▒e▒M▒5|▒Ȓ;▒▒▒=▒<])_▒pڔ▒▒▒D▒▒▒írU$▒E▒+' 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 1: $'PK\003\004': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 2: $'\b\245f\213E': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 3▒f▒E2▒f▒ZgMETA-K-*▒▒ϳR0▒3▒▒r▒Cq,HL▒HU▒%-▒Lx▒▒▒RKRSt▒*A▒▒▒ 
▒͍t▒ 
M4▒▒sR▒▒: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 4: $'\362\213\022K\200\3725y\271x\271PK\003\004': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 5:{f▒Ecom/PK: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 6: f▒E com/github/PK: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 6: $'\b': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 7: f▒Ecom/github/aliteralmind/PK: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 7: $'\b': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 8: syntax error near unexpected token `$'com/github/aliteralmind/templatefeather/PK\003\004'' 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/templatefeather-0.1.1.2.jar: line 8: |f▒E(com/github/aliteralmind/templatefeather/PK' 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 1: $'PK\003\004': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 2: $'\b\214f\213E': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 3▒f▒E2▒f▒ZgMETA-INF/MANIFEK-*▒▒ϳR0▒3▒▒r▒Cq,HL▒HU▒%-▒Lx▒▒▒RKRSt▒*A▒▒▒ 
▒͍t▒ 
M4▒▒sR▒▒: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 4: $'\362\213\022K\200\3725y\271x\271PK\003\004': command not found 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 5:tf▒Ecom/PK: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 6:tf▒E com/github/PK: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 7:zf▒Ecom/github/xbn/PK: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 8:tf▒Ecom/github/xbn/analyze/PK: No such file or directory 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 9: syntax error near unexpected token `$'ʭ\210\342A'' 
/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar: line 9:tf▒E▒U▒M_-com/github/xbn/analyze/AbstractAnalyzer.class▒▒yS▒@Ɵ▒j!(ʭ▒▒A' 
(djauth_venv)[email protected]:~/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build$ PuTTY 

今天早些時候,我順利地通過SFTP我的Windows機器上執行此操作。這是非常緩慢的,但它的工作原理。我需要做什麼才能在Ubuntu中直接執行此操作?

謝謝。


更新基於意見,回答

謝謝@Alex和@ChrisStratton。再次使罐非可執行文件,並使用冒號後,我不再得到胡言亂語,但它仍然給我

Exception in thread "main" java.lang.NoClassDefFoundError: com/github/xbn/io/PlainTextFileUtil 
at BuildPartFour.main(BuildPartFour.java:14) 
Caused by: java.lang.ClassNotFoundException: com.github.xbn.io.PlainTextFileUtil`. 

這個類是確實在罐子:

$7z l /home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar 

7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18 
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,1 CPU) 

Listing archive: /home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar 


-- 
Path = /home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava-0.1.5.jar 

Type = zip 
Physical Size = 665303 

    Date  Time Attr   Size Compressed Name 
------------------- ----- ------------ ------------ ------------------------ 
2014-12-11 12:52:24 D....   0   0 META-INF 
2014-12-11 12:52:22 .....   103   90 META-INF/MANIFEST.MF 
2014-12-11 12:51:40 D....   0   0 com 
2014-12-11 12:51:40 D....   0   0 com/github 
2014-12-11 12:51:52 D....   0   0 com/github/xbn 

... 

2014-12-11 12:51:40 .....   5523   2651 com/github/xbn/io/IOUtil.class 
2014-12-11 12:51:40 .....   2483   1098 com/github/xbn/io/MultiTextAppender.class 
2014-12-11 12:51:40 .....   2018   865 com/github/xbn/io/NewPrintWriterToFile.class 
2014-12-11 12:51:40 .....   2497   927 com/github/xbn/io/NewTextAppenderFor.class 
2014-12-11 12:51:40 .....   1687   685 com/github/xbn/io/NewTextAppenterFor.class 
2014-12-11 12:51:40 .....   5655   2311 com/github/xbn/io/PathMustBe.class 
2014-12-11 12:51:40 .....   2250   906 com/github/xbn/io/PlainTextFileUtil.class 
2014-12-11 12:51:40 .....   1656   871 com/github/xbn/io/PrintStreamForString.class 
2014-12-11 12:51:40 .....   458   292 com/github/xbn/io/RTAccessDeniedException.class 
2014-12-11 12:51:40 .....   450   288 com/github/xbn/io/RTEndOfFileException.class 
2014-12-11 12:51:40 .....   458   288 com/github/xbn/io/RTFileNotFoundException.class 

... 

------------------- ----- ------------ ------------ ------------------------ 
           1437122  545645 621 files, 49 folders 

上午什麼我仍然失蹤?

+2

你不執行'.jar' - Java只是需要訪問,它看起來像是類文件已損壞 –

+2

是 - 分號導致unix shell將jar視爲不同的命令。使用冒號。請參閱http://stackoverflow.com/questions/4528438/classpath-does-not-work-under-linux –

+0

可能重複的[Classpath不能在Linux下工作](http://stackoverflow.com/questions/4528438/classpath -does-not-work-under-linux) –

回答

5

的罐子不需要可執行

在Windows中,語義

java -classpath somejar1.jar;somejar2.jar 

但在* NIX,語義是

java -classpath somejar1.jar:somejar2.jar 

* NIX需要冒號(: )不是分號(;)。

UPDATE

它看起來像你的命令不正確的結構,你說你這樣做:

java BuildPartFour -classpath (...) 

如果我假設BuildPartFour是當前工作.class文件目錄。這將導致在運行您的BuildPartFour類傳遞-classpath (...)作爲參數傳遞給你的程序(這些將是可見的public static void main(String[] args) args數組中

它應該是這樣的:

java -classpath (...) BuildPartFour 

一般java命令結構是:

java [options] [class] [args] 
+0

我已更新該問題。這使我進一步邁出了重要的一步。 – aliteralmind

+0

是的,這個。目前'-classpath'作爲參數傳遞給應用程序,而不是** JVM。 –

+0

就是這樣。我忘記了基礎知識。實際上,有必要添加一個「。」到類路徑中,以便找到要執行的類本身。 – aliteralmind