2009-10-11 330 views
0

可以有人解釋我如何創建jar文件。我的源文件夾有各種子文件夾和圖像文件。您可以從以下網址中看到解釋源文件夾結構的圖像 http://img63.imageshack.us/gal.php?g=capturev.png。 當使用eclipse export jar函數創建jar時,它只包含類文件,但是我想爲我的源文件夾中的所有內容創建jar文件。第三張圖片顯示了我在創建jar時獲得的窗口。它沒有其他文件夾和圖像可供選擇。創建jar文件

+0

你能告訴我們您正在使用的Eclipse版本? – 2009-10-11 14:16:40

+0

我正在爲Web開發人員使用Eclipse Java EE IDE。它沒有版本NO – KItis 2009-10-11 15:48:11

+0

eclipse-jee-galileo,這是名字,它是伽利略 – KItis 2009-10-11 16:02:20

回答

2

你可以在命令行中使用jar命令做到這一點:

Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ... 
Options: 
    -c create new archive 
    -t list table of contents for archive 
    -x extract named (or all) files from archive 
    -u update existing archive 
    -v generate verbose output on standard output 
    -f specify archive file name 
    -m include manifest information from specified manifest file 
    -e specify application entry point for stand-alone application 
     bundled into an executable jar file 
    -0 store only; use no ZIP compression 
    -M do not create a manifest file for the entries 
    -i generate index information for the specified jar files 
    -C change to the specified directory and include the following file 
If any file is a directory then it is processed recursively. 
The manifest file name, the archive file name and the entry point name are 
specified in the same order as the 'm', 'f' and 'e' flags. 

Example 1: to archive two class files into an archive called classes.jar: 
     jar cvf classes.jar Foo.class Bar.class 
Example 2: use an existing manifest file 'mymanifest' and archive all the 
      files in the foo/ directory into 'classes.jar': 
     jar cvfm classes.jar mymanifest -C foo/ . 

但就個人而言,我會使用類似Ant或Maven用於這一目的。

5

查看太陽jar tutorial

雖然你可以從命令行運行jar,但我建議使用Ant和Ant Jar task。它會給你更多的控制如何構建jar文件以及包含哪些內容。

例如

<jar destfile="${dist}/lib/app.jar" 
     basedir="${build}/classes" 
     excludes="**/Test.class" 
    /> 

將建立在classes目錄一切都變成.jar文件,但排除Test類。