网站首页 > 文章中心 > 其它

怎么给java代码打包

作者:小编 更新时间:2023-08-13 07:32:07 浏览量:485人看过

java如何打包

此工具用java编写,跨平台,能实现很多功能:编译、打包、运行、文件操作、数据库操作、自定义任务等.

主要使用方法:在工程目录下编写build.xml配置文件,然后运行ant即可:

怎么给java代码打包-图1

#ant

#java -jar ant.jar

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"/

怎么给java代码打包-图2

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}"/

property="AnakiaTask.present"/

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

!-- 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}"/

!-- examples target. Compiles the example classes. --

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

description="Compiles the example classes."

includes="examples/**"

!-- tools target. Compiles the tool classes. --

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

description="Compiles the tool classes."

includes="tools/**"

!-- 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}"

!-- 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"

/section

/manifest

/jar

!-- 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"

bottom="Copyright ? ${year} Apache Software Foundation. All Rights Reserved."

/javadoc

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

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

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

!-- 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

include name="*.jar"/

/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"

/anakia

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

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

include name="**/*.gif"/

include name="**/*.jpeg"/

include name="**/*.jpg"/

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"/

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

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

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

include name="**/*.class"/

!-- 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}"/

!-- 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/**"/

!-- 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"/

!-- 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"/

!-- 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"/

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

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

!-- 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

/project

build.xml文件的编写可参见ant发行版中的使用文档

你也可以自己编写脚本打包,使用jdk发行版中的jar命令,例如:

#jar cmf myManifestFile myFile.jar *.class

注意还需要自己编写MANIFEST.MF文件配置包属性.具体可以参见javadoc

当然还可以使用集成开发环境提供的打包工具,如JBuilder提供打包工具,但这样程序的移植性不强,建议不要使用,就使用ant比较好.

怎样将编译好的java程序打包成可执行文件?

步骤:1、将Java项目导出成.jar包,鼠标右键项目名,选择导出

怎么给java代码打包-图3

①.0、最后为EXE文件命名和更换图标

①.1、成功生成!

怎样将java源代码打包成可执行jar文件或exe文件

如何将java源码打包成exe

将java源码打包成exe的步骤如下:

①.、最简单直接的方法,选择想打包的程序,右键export;

如何把java程序打包成.jar?

打包成一般的jar包的步骤如下:

①输入如下命令即可:

Cmd代码

jar

cvf

counter.jar

-C

bin

.

其中,"-C

bin"实际上是告诉jar命令先cd到bin目录下,再在此目录执行没有参数"-C

bin"的命令,等价于:

cd

//

"."代表当前路径

如何将java源程序打包成可执行文件

把 java项目 打包成 exe 可执行文件! 打包跨平台的.exe文件.安装后运行左窗窗口标有十步.?

第1步 : 完全略过,直接点Next

以上就是土嘎嘎小编为大家整理的怎么给java代码打包相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章