打包java,打包java項目為jar包

本文目錄一覽:

JAVA程序怎樣打包

第一:普通類導出jar包,我說的普通類就是指此類包含main方法,並且沒有用到別的jar包。

1.在eclipse中選擇你要導出的類或者package,右擊,選擇Export子選項;

2.在彈出的對話框中,選擇java文件—選擇JAR file,單擊next;

3.在JAR file後面的文本框中選擇你要生成的jar包的位置以及名字,注意在Export generated class files and resources和Export java source files and resources前面打上勾,單擊next;

4.單擊兩次next按鈕,到達JAR Manifest Specification。注意在最底下的Main class後面的文本框中選擇你的jar包的入口類。單擊Finish,完成。

你可以在dos環境下,進入你的jar所在的目錄,運行 java -jar 名字.jar,檢測運行是否正確。

第二、你所要導出的類裡邊用到了別的jar包。比如說你寫的類連接了數據庫,用到數據庫驅動包oracl.jar.。

1.先把你要導出的類按照上面的步驟導出形成jar包,比如叫test.jar

2.新建一個文件夾main,比如在D盤根目錄下;

3.把test.jar和oracl.jar拷貝到main文件下,右擊test.jar,解壓到當前文件夾。把META-INF\MANIFEST.MF剪切到另外一個地方 (比如是桌面!) ;

4.右擊oracl.jar,解壓到當前文件夾。

5.在dos環境下,進入到D盤的main文件夾下,執行 jar cvfm new.jar meta-inf/manifest.mf .,不要忘了最後面的點。

6.用壓縮工具打開你新生成的new.jar,用你放在桌面的META-INF\MANIFEST.MF覆蓋new.jar原有。

你可以在dos環境下,進入你的jar所在的目錄,運行 java -jar 名字.jar,檢測運行是否正確。

怎麼把java類打包成

使用Eclipse的Export功能:

一、打包成一般的jar包:

步驟如下:

1)在要打包的項目上右擊,選擇Export

2)在彈出的窗口中,選擇Java – JAR File,然後點擊next按鈕

3)在JAR File Specification窗口中,設置打包成的文件名和存放位置,點擊兩側next

4)在JAR Manifest Specification窗口中,設置MANIFEST.MF清單文件的配置,

若僅僅打包成單純的jar包的話,不用做任何修改,採取默認即可

若打包成可執行jar包的話,可以使用已存在的MANIFEST文件或者直接選擇Main class

5)點擊Finish按鈕,完成打包。

二、打包成可運行的jar包

步驟如下:

1)在要打包的項目上右擊,選擇Export

2)在彈出的窗口中,選擇Java – Runnable JAR File,然後點擊next按鈕

3)在Runnable JAR File Specification窗口中,選擇Launch configuration和Export destination

4)點擊Finish按鈕,打包完成。

java程序如何打包成apk?

首先下載eclipse與android插件,安裝完畢後,建立android項目,編碼完成後,生成keystore,使用jdk自帶的keytoo l-genkey -aliasandroid.keystore -keyalg RSA -validity 100000 -eystore android.keystore\x0d\x0a\x0d\x0a然後選擇要打包的項目,右鍵點擊_Androidtools_Export Signed Application Package,選擇哪個項目,下一步後,選擇剛才生成的那個key和生成時錄入的密碼,下一步設置輸出位置。\x0d\x0a完成APK生成。\x0d\x0a\x0d\x0aWEB項目不可能生成APK ,如果你現有項目可以把相關的源碼文件複製到新建的android項目內,但是lib包有可能不支持,要看你用了那裡lib。

怎樣將編譯好的java程序打包成可執行文件?

需要的工具myeclipse 、jar2exe

步驟:1、將Java項目導出成.jar包,鼠標右鍵項目名,選擇導出

2、導出的方式選擇Runnable JAR file,點擊next繼續

3、選擇導出文件的路徑

4、 jar文件成功導出到桌面

5、用工具將jar文件打包成EXE可執行文件,選擇剛才導出的jar文件

6、選擇要導出程序的類型

7、選擇主類,圖片可不選

8、導出程序的具體設置

9、 選擇輔助jar文件沒有則不選

10、最後為EXE文件命名和更換圖標

11、成功生成!

java如何打包

建議使用ANT打包工具,下載地址:

此工具用java編寫,跨平台,能實現很多功能:編譯、打包、運行、文件操作、數據庫操作、自定義任務等。

主要使用方法:在工程目錄下編寫build.xml配置文件,然後運行ant即可:

#ant

#java -jar ant.jar

下面給你提供一個例子,是jakarta-oro-2.0.8的包的build.xml

?xml version=”1.0″?

project default=”jar”

!– Allow properties following these statements to be overridden —

!– Note that all of these don’t have to exist. They’ve just been defined

incase they are used. —

property file=”build.properties”/

!–

property file=”.ant.properties”/

property file=”${user.home}/.ant.properties”/

property file=”default.properties”/

!– prepare target. Creates build directories. —

target name=”splash”

splash imageurl=”./ant_logo_medium.gif”/

/target

target name=”prepare” depends=”splash” description=”Creates build directories.”

tstamp

format property=”DATE” pattern=”yyyy-MM-dd hh:mm:ss” /

/tstamp

mkdir dir=”${build.dest}”/

mkdir dir=”${build.dest}/META-INF”/

copy todir=”${build.dest}/META-INF”

fileset dir=”${top.dir}”

include name=”LICENSE”/

/fileset

/copy

mkdir dir=”${build.tests}”/

available file=”${jakarta-site2.dir}/lib” type=”dir”

property=”AnakiaTask.present”/

/target

target name=”prepare-error” depends=”prepare”

description=”Prints error message for prepare target.”

unless=”AnakiaTask.present”

echo

AnakiaTask is not present! Please check to make sure that

velocity.jar is in your classpath.

/echo

/target

!– lib target. Compiles the library classes only —

target name=”lib” depends=”prepare”

description=”Compiles the library classes only.”

javac srcdir=”${build.src}”

destdir=”${build.dest}”

excludes=”examples/**,tools/**”

debug=”${debug}”

deprecation=”${deprecation}”

optimize=”${optimize}”/

/target

!– examples target. Compiles the example classes. —

target name=”examples” depends=”prepare,lib”

description=”Compiles the example classes.”

javac srcdir=”${build.src}”

destdir=”${build.dest}”

includes=”examples/**”

debug=”${debug}”

deprecation=”${deprecation}”

optimize=”${optimize}”/

/target

!– tools target. Compiles the tool classes. —

target name=”tools” depends=”prepare,lib”

description=”Compiles the tool classes.”

javac srcdir=”${build.src}”

destdir=”${build.dest}”

includes=”tools/**”

debug=”${debug}”

deprecation=”${deprecation}”

optimize=”${optimize}”/

/target

!– tests target. Compiles and runs the unit tests. —

target name=”tests” depends=”prepare,lib”

description=”Compiles and runs the unit tests.”

javac srcdir=”${build.src}/tests”

destdir=”${build.tests}”

debug=”${debug}”

deprecation=”${deprecation}”

optimize=”${optimize}”/

/target

!– jar target. Compiles the source directory and creates a .jar file —

target name=”jar” depends=”lib” description=”Compiles the source directory and creates a .jar file.”

jar jarfile=”${top.dir}/${final.name}.jar”

basedir=”${build.dest}”

includes=”org/**,META-INF/**”

excludes=”**/package.html,**/overview.html”

manifest

section name=”org/apache/oro”

attribute name=”Specification-Title”

value=”Jakarta ORO” /

attribute name=”Specification-Version”

value=”${version}” /

attribute name=”Specification-Vendor”

value=”Apache Software Foundation” /

attribute name=”Implementation-Title”

value=”org.apache.oro” /

attribute name=”Implementation-Version”

value=”${version} ${DATE}” /

attribute name=”Implementation-Vendor”

value=”Apache Software Foundation” /

/section

/manifest

/jar

/target

!– javadocs target. Creates the API documentation —

target name=”javadocs” depends=”prepare”

description=”Creates the API documentation.”

mkdir dir=”${javadoc.destdir}”/

javadoc packagenames=”org.apache.oro.io,org.apache.oro.text,org.apache.oro.text.regex,org.apache.oro.text.awk,org.apache.oro.text.perl,org.apache.oro.util”

sourcepath=”${build.src}”

destdir=”${javadoc.destdir}”

overview=”${build.src}/org/apache/oro/overview.html”

author=”true”

version=”true”

windowtitle=”${name} ${version} API”

doctitle=”${name} ${version} API”

header=”a href=” target=_topimg src='{@docroot}/../images/logoSmall.gif’ alt=’Jakarta ORO’ width=48 height=47 align=center border=0 hspace=1 vspace=1/a”

bottom=”Copyright © ${year} Apache Software Foundation. All Rights Reserved.”

/javadoc

replace file=”${javadoc.destdir}/overview-frame.html”

token=”{@docroot}” value=”.”/

replace dir=”${javadoc.destdir}” includes=”**/*.html”

token=”@version@” value=”${version}”/

/target

!– docs target. Creates project web pages and documentation. —

target name=”docs” depends=”prepare-error,lib,examples”

description=”Creates the project web pages and documentation.”

if=”AnakiaTask.present”

taskdef name=”anakia” classname=”org.apache.velocity.anakia.AnakiaTask”

classpath

fileset dir=”${jakarta-site2.dir}/lib”

include name=”*.jar”/

/fileset

/classpath

/taskdef

anakia basedir=”${docs.src}” destdir=”${docs.dest}/”

extension=”.html” style=”./site.vsl”

projectFile=”stylesheets/project.xml”

excludes=”**/stylesheets/** manual/** empty.xml”

includes=”**/*.xml”

lastModifiedCheck=”true”

templatePath=”${jakarta-site2.dir}/xdocs/stylesheets”

/anakia

copy todir=”${docs.dest}/images” filtering=”no”

fileset dir=”${docs.src}/images”

include name=”**/*.gif”/

include name=”**/*.jpeg”/

include name=”**/*.jpg”/

/fileset

/copy

mkdir dir=”${docs.dest}/classes”/

mkdir dir=”${docs.dest}/classes/examples”/

copy todir=”${docs.dest}/classes/examples” filtering=”no”

fileset dir=”${build.dest}/examples”

include name=”MatcherDemoApplet.class”/

/fileset

/copy

mkdir dir=”${docs.dest}/classes/org”/

copy todir=”${docs.dest}/classes/org” filtering=”no”

fileset dir=”${build.dest}/org”

include name=”**/*.class”/

/fileset

/copy

/target

!– package target —

target name=”package” depends=”jar,javadocs,docs”

description=”Creates a distribution directory tree.”

mkdir dir=”${final.dir}”/

copy todir=”${final.dir}/src”

fileset dir=”${code.src}”/

/copy

!– BEGIN_REMOVE_THIS —

!– Remove this when there’s a first draft of the manual. —

copy todir=”${final.dir}/docs”

fileset dir=”${docs.dest}”

exclude name=”manual/**”/

/fileset

/copy

!– END_REMOVE_THIS —

copy file=”${top.dir}/build.xml” tofile=”${final.dir}/build.xml”/

copy file=”${top.dir}/build.properties”

tofile=”${final.dir}/build.properties”/

copy file=”${top.dir}/LICENSE” tofile=”${final.dir}/LICENSE”/

copy file=”${top.dir}/ISSUES” tofile=”${final.dir}/ISSUES”/

copy file=”${top.dir}/CHANGES” tofile=”${final.dir}/CHANGES”/

copy file=”${top.dir}/COMPILE” tofile=”${final.dir}/COMPILE”/

copy file=”${top.dir}/CONTRIBUTORS”

tofile=”${final.dir}/CONTRIBUTORS”/

copy file=”${top.dir}/README” tofile=”${final.dir}/README”/

copy file=”${top.dir}/STYLE” tofile=”${final.dir}/STYLE”/

copy file=”${top.dir}/TODO” tofile=”${final.dir}/TODO”/

copy file=”${top.dir}/${final.name}.jar” tofile=”${final.dir}/${final.name}.jar”/

/target

!– package-zip target. Packages the distribution with ZIP —

target name=”package-zip” depends=”package”

description=”Packages the distribution as a zip file.”

zip zipfile=”${top.dir}/${final.name}.zip” basedir=”${top.dir}/”

includes=”**/${final.name}/**” excludes=”**/.cvsignore”/

/target

!– Packages the distribution with TAR-GZIP —

target name=”package-tgz” depends=”package”

description=”Packages the distribution as a gzipped tar file.”

tar tarfile=”${top.dir}/${final.name}.tar”

basedir=”${top.dir}” excludes=”**/**”

tarfileset dir=”${final.dir}/..”

include name=”${final.name}/**”/

exclude name=”**/.cvsignore”/

/tarfileset

/tar

gzip zipfile=”${top.dir}/${project}-${version}.tar.gz” src=”${top.dir}/${project}-${version}.tar”/

/target

!– Packages the distribution with ZIP and TAG-GZIP —

target name=”package-all” depends=”package-zip, package-tgz”

/target

!– Makes an attempt to clean up a little. —

target name=”clean”

description=”Removes generated artifacts from source tree.”

delete dir=”${build.dest}”/

delete dir=”${javadoc.destdir}”/

delete dir=”${final.dir}”/

delete file=”${top.dir}/${final.name}.jar”/

delete file=”${top.dir}/${final.name}.tar”/

delete file=”${top.dir}/${final.name}.tar.gz”/

delete file=”${top.dir}/${final.name}.zip”/

delete

fileset dir=”${top.dir}” includes=”velocity.log*”/

/delete

/target

/project

build.xml文件的編寫可參見ant發行版中的使用文檔

你也可以自己編寫腳本打包,使用jdk發行版中的jar命令,例如:

#jar cmf myManifestFile myFile.jar *.class

注意還需要自己編寫MANIFEST.MF文件配置包屬性。具體可以參見javadoc

當然還可以使用集成開發環境提供的打包工具,如JBuilder提供打包工具,但這樣程序的移植性不強,建議不要使用,就使用ant比較好。

怎麼把java文件打包

1、右鍵要導出的項目,選擇Export

2、選擇Java — JAR file

3、選擇要打包的文件,和存放路徑,點擊Finish

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/308324.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2025-01-03 14:48
下一篇 2025-01-03 14:48

相關推薦

  • Java JsonPath 效率優化指南

    本篇文章將深入探討Java JsonPath的效率問題,並提供一些優化方案。 一、JsonPath 簡介 JsonPath是一個可用於從JSON數據中獲取信息的庫。它提供了一種DS…

    編程 2025-04-29
  • java client.getacsresponse 編譯報錯解決方法

    java client.getacsresponse 編譯報錯是Java編程過程中常見的錯誤,常見的原因是代碼的語法錯誤、類庫依賴問題和編譯環境的配置問題。下面將從多個方面進行分析…

    編程 2025-04-29
  • Java騰訊雲音視頻對接

    本文旨在從多個方面詳細闡述Java騰訊雲音視頻對接,提供完整的代碼示例。 一、騰訊雲音視頻介紹 騰訊雲音視頻服務(Cloud Tencent Real-Time Communica…

    編程 2025-04-29
  • Java Bean加載過程

    Java Bean加載過程涉及到類加載器、反射機制和Java虛擬機的執行過程。在本文中,將從這三個方面詳細闡述Java Bean加載的過程。 一、類加載器 類加載器是Java虛擬機…

    編程 2025-04-29
  • Java Milvus SearchParam withoutFields用法介紹

    本文將詳細介紹Java Milvus SearchParam withoutFields的相關知識和用法。 一、什麼是Java Milvus SearchParam without…

    編程 2025-04-29
  • Java 8中某一周的周一

    Java 8是Java語言中的一個版本,於2014年3月18日發佈。本文將從多個方面對Java 8中某一周的周一進行詳細的闡述。 一、數組處理 Java 8新特性之一是Stream…

    編程 2025-04-29
  • Java判斷字符串是否存在多個

    本文將從以下幾個方面詳細闡述如何使用Java判斷一個字符串中是否存在多個指定字符: 一、字符串遍歷 字符串是Java編程中非常重要的一種數據類型。要判斷字符串中是否存在多個指定字符…

    編程 2025-04-29
  • 掌握magic-api item.import,為你的項目注入靈魂

    你是否曾經想要導入一個模塊,但卻不知道如何實現?又或者,你是否在使用magic-api時遇到了無法導入的問題?那麼,你來到了正確的地方。在本文中,我們將詳細闡述magic-api的…

    編程 2025-04-29
  • VSCode為什麼無法運行Java

    解答:VSCode無法運行Java是因為默認情況下,VSCode並沒有集成Java運行環境,需要手動添加Java運行環境或安裝相關插件才能實現Java代碼的編寫、調試和運行。 一、…

    編程 2025-04-29
  • Java任務下發回滾系統的設計與實現

    本文將介紹一個Java任務下發回滾系統的設計與實現。該系統可以用於執行複雜的任務,包括可回滾的任務,及時恢復任務失敗前的狀態。系統使用Java語言進行開發,可以支持多種類型的任務。…

    編程 2025-04-29

發表回復

登錄後才能評論