2012-07-01 154 views
4

我是ubuntu 10.10的新手,並且正在使用它作爲虛擬機。我試着安裝jdk 1.7從終端運行java程序。我遵循鏈接中的說明:How to Install Oracle Java on Ubuntu Linux。安裝完成後,我試着運行一個Hello World java程序。程序編譯成功,當我做javac Hello.java。然而,當我試圖運行使用java Hello程序,它並沒有給終端上的任何輸出,給了我下面的:在Ubuntu 10.10上安裝jdk1.7.0

Unable to launch the application.

例外:

CouldNotLoadArgumentException[ Could not load file/URL specified: Hello] 
at com.sun.javaws.Main.launchApp(Unknown Source) 
at com.sun.javaws.Main.continueInSecureThread(Unknown Source) 
at com.sun.javaws.Main$1.run(Unknown Source) 
at java.lang.Thread.run(Thread.java:722)  

包裝異常

java.io.FileNotFoundException: Hello (No such file or directory) 
at java.io.FileInputStream.open(Native Method) 
at java.io.FileInputStream.<init>(FileInputStream.java:138) 
at java.io.FileInputStream.<init>(FileInputStream.java:97) 
at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source) 
at com.sun.javaws.Main.launchApp(Unknown Source) 
at com.sun.javaws.Main.continueInSecureThread(Unknown Source) 
at com.sun.javaws.Main$1.run(Unknown Source) 
at java.lang.Thread.run(Thread.java:722) 

此外,我試圖使用java -version檢查我的版本java,它給出了以下輸出:

Java(TM) Web Start 10.0.0.147-fcs 
Usage: javaws [run-options] <jnlp-file>  
     javaws [control-options]   
    where run-options include:   
    -verbose   display additional output 
    -offline   run the application in offline mode 
    -system   run the application from the system cache only 
    -Xnosplash  run without showing a splash screen 
    -J<option>  supply option to the vm 
    -wait    start java process and wait for its exit  

control-options include:  
    -viewer   show the cache viewer in the java control panel 
    -clearcache  remove all non-installed applications from the cache 
    -uninstall  remove all applications from the cache 
    -uninstall <jnlp-file>    remove the application from the cache 
    -import [import-options] <jnlp-file> import the application to the cache 

import-options include:      
    -silent   import silently (with no user interface)  
    -system   import application into the system cache  
    -codebase <url> retrieve resources from the given codebase 
    -shortcut   install shortcuts as if user allowed prompt 
    -association  install associations as if user allowed prompt 

我在這裏看到它使用javaws當我嘗試運行程序使用java

我不明白爲什麼會發生這種情況或發生了什麼問題。任何幫助將非常感激。我只是Ubuntu上的初學者。 在此先感謝!


編輯1 Hello.java:

public class Hello 
{ 
    public static void main(String... s) 
    { 
     System.out.println("Hello World.!!!"); 
    } 
} 
+0

你需要顯示'Hello.java'。 – Starkey

+0

我現在已經提供了這個問題作爲編輯。 – akaHuman

+1

奇怪,請問爲什麼你使用Ubuntu 10.10(相當過時)?如果從安裝目錄中調用java,輸出是什麼? – home

回答

1

您從java -version的輸出爲您提供javaws -version的輸出。 所以這似乎是您的文件系統中的鏈接錯誤。 如果使用update-alternatives,則可以在二進制文件夾(/ usr/bin)中創建一個符號鏈接。 也許你在閱讀教程時遇到了一些錯字? 我很確定這是類似 sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_05/bin/javaws" 1或類似的東西。

您可以嘗試重新輸入「update-alternative」命令。

0

我不知道你想在10.10 12.04是可用的。我安裝了Sun/Oracle版本,並且它第一次運行。您只需下載它,解壓縮並將其添加到您的路徑中即可。

錯誤消息表明Java安裝不正確。

我建議你也安裝一個像IntelliJ CE這樣的免費IDE。這將使編寫,編譯,運行和調試應用程序變得更容易。