Ubuntu12.04下jamvm1.5.4+classpath-0.98成功執行 helloworld.class

來源:互聯網
上載者:User

標籤:style   http   io   ar   os   java   sp   for   strong   

經過兩天的努力,總於在ubuntu以下編譯好classpath-0.98與jamvm1.5.4,並能成功的運行類檔案:jamvm hellowold,當螢幕上列印出“hello world!”的時候,按捺不住一陣興奮!在這兩天中,運行jamvm hellowold始終被有三類異常:

1) Exceptionoccurred while VM initialising
java/lang/NoClassDefFoundError: java/lang/Thread 

2) Exception occured while printing exception(java/lang/NoClassDefFoundError)... 

Original exception wasjava/lang/UnsatisfiedLinkError 

3)segment fault

對於當中異常1), 2) 我猜測可能是classpath等路徑設錯,我通過baidu,google,bing等搜尋工具查詢國內外相關問題,得出一個解決方案是:

通過jamvm –version 命令查詢路徑資訊:

$ jamvm-version

javaversion "1.5.0"

JamVMversion 1.5.4

Copyright(C) 2003-2010 Robert Lougher <[email protected]>

Thisprogram is free software; you can redistribute it and/or

modify itunder the terms of the GNU General Public License

aspublished by the Free Software Foundation; either version 2,

or (atyour option) any later version.

 

Thisprogram is distributed in the hope that it will be useful,

butWITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.  Seethe

GNUGeneral Public License for more details.

Buildinformation:

ExecutionEngine: inline-threaded interpreter with stack-caching

Compiledwith: gcc 4.6.3

BootLibrary Path: /usr/local/classpath/lib/classpath

BootClass Path:

 /usr/local/jamvm/share/jamvm/classes.zip:/usr/local/classpath/share/classpath/glibj.zip

在運行jamvm helloword之前須要設定兩個變數:

export LD_LIBRARY_PATH=/usr/local/classpath/lib/classpath:$LD_LIBRARY_PATH

export  BOOTCLASSPATH=/usr/local/jamvm/share/jamvm/classes.zip:/usr/local/classpath/share/classpath/glibj.zip

 

可是我依照這樣的方法來設定兩個環境變數,還是解決不了問題;

關於異常3) 這個一定是jamvm本身的bug,除非單步調試,否則可能無法定位其問題,況且即使定位,也絕對無法解決。

在一籌莫展之時,突然搜尋到一篇國際友人文章,該貼對我的成功起了決定性的作用,真是山重水複疑無路,柳暗花明又一村!!!感謝該貼的作者!url例如以下:

http://www.webos-internals.org/wiki/Building_JamVM_and_GNU_Classpath_and_Jikes_(for_Java_support_in_webOS)_with_scratchbox2

詳細來說,該文提到一個非常關鍵的地方,就是在編jamvm的時候,須要enable libffi模組,否則會引起段錯誤! 

我依照該文的步驟,一步一步走下來,終於得到了自己想要的結果!該文的應該用情境是arm,而且能夠帶gui,gtk等應用,而我的應用程式情境比較簡單,即在x86以下不帶gui的應用,故而我的編譯和他有一些區別,詳細過程例如以下:

1.       classpath相關操作

$ cd ~/work/free

$ wget ftp://ftp.gnu.org/gnu/classpath/classpath-0.98.tar.gz

$ tar xzvf classpath-0.98.tar.gz

$ cd classpath-0.98

$ ./configure--disable-examples --without-x --disable-qt-peer --disable-gtk-peer--disable-gconf-peer --disable-plugin --disable-alsa --disable-dssi

$ make -i

$ sudo make install -i

注: classpath的預設安裝路徑為/usr/local/classpath

 

2.       jamvm相關操作

$ cd ~/work/free

$ wget ftp://sourceware.org/pub/libffi/libffi-3.0.10.tar.gz

$ tar xzvf libffi-3.0.10.tar.gz

$ cd libffi-3.0.10

$ ./configure--prefix=/usr/local

$ make

$ sudo make install

$ sudo cp include/ffi_common.h /usr/local/include/

$cd i686-pc-linux-gnu/

$ cd include/

$ sudo cp ffi.h /usr/local/include

$ cd ../src/86

$ sudo cp ffitarget.h /usr/local/include

$ cd ~/work/free

$ wget http://freefr.dl.sourceforge.net/project/jamvm/jamvm/JamVM%201.5.4/jamvm-1.5.4.tar.gz

$ tar xzvf jamvm-1.5.4.tar.gz

$ cd jamvm-1.5.4

$ CPPFLAGS="-I/usr/local/include"

$ ./configure --with-classpath-install-dir=/usr/local/classpath -enable-ffi

$ make

$ sudo make install


3.       驗證jamvm

1> 已知源碼~/work/free/jamvm-1.5.4/java/helloworld.java:

public class helloworld {

    public static void main(String[] args) {

        System.out.println(“hello world!”);

    }

}

 

2> 編譯 javac helloworld.java

生產helloworld.class

 

3> 運行jamvm helloworld 列印結果:

helloworld!

 

此時我們在查看CLASSPATH, LD_LIBRARY_PATH,發現:

[email protected]:~$echo $CLASSPATH

 

[email protected]:~$echo $LD_LIBRARY_PATH

:/usr/local/lib

 

cd ~/work/free/jamvm-1.5.4/java/

[email protected]:~/work/free/jamvm-1.5.4/java$jamvm helloworld

helloworld!

能夠看到,CLASSPATH與LD_LIBRARY_PATH並不須要設定成之前說的, jamvm –version顯示的那些路徑!!!

 

最後,希望該文能對遇到相同問題的兄弟們起到一定協助!

Ubuntu12.04下jamvm1.5.4+classpath-0.98成功執行 helloworld.class

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.