「java打包文件」java打包文件夹并下载

博主:adminadmin 2022-11-29 21:18:09 65

今天给各位分享java打包文件的知识,其中也会对java打包文件夹并下载进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

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

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

1.输入如下命令即可:

Cmd代码

jar

cvf

counter.jar

-C

bin

.

其中,“-C

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

bin”的命令,等价于:

2.Cmd代码

cd

bin

jar

cvf

counter.jar

.

//

"."代表当前路径

怎样java 打包成exe文件

右击你的项目,选择Export:

选择Java目录下的JAR file:

设置导出jar文件的路径,我这里选择的是桌面,点击Next:

这一步默认,不用改动,直接Next:

设置项目的主类,也就是项目的入口,点击Finish:

这就是生成的jar文件:

下面需要一个名叫exe4j的软件,可以自行去网上下载,下载好该软件后打开进入主页面,直接点击Next:

这一步选择第二项"JAR in EXE" mode:

填写应用的简称,和转换后exe文件的路径,我这里让然是选择的桌面:

这一步填写生成exe文件的名称:

点击"+"号添加刚才生成的jar文件:

添加jar文件后设置程序的入口:

填写最低版本,最高版本可以为空:

到这一步就可以直接点击Finish了:

这就是生成的exe文件:

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程序打包成可执行文件?

需要的工具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程序打包成安装文件

一,下载inno setup

二,下载jre..去java官方下载

.这个是我将要打包的目录(netbeans编译后的dist文件夹)

然后把jre和相关的东东放进去,然后在里面加入一个go.cmd(bat)(名字随意啦)

Java代码

@echo off

echo 请稍后..安装Java运行环境ing

'如果没有java命令 则安装jre

java||jre-6u20-windows-i586.exe /q /norestart

start /MIN javaw -jar AutoCheckOut.jar

代码就像这样

解释下这里..

java||jre-6u20-windows-i586.exe /q /norestart

意思是..如果java这个命令执行不成功..则执行后面那句jre-6u20-windows-i586.exe /q /norestart

这句话是在安静模式下安装jre,没有对话框

这部完成后

start /MIN javaw -jar AutoCheckOut.jar

可以让我们的java程序在一个没有控制台的方式运行

然后你的目录大概就是这样的

好了.改下一步了

四,用inno创建setup.exe

打开inno

用向导创建

之后一步一步到这里

注意添加文件和文件夹 你添加的部分都是作为应用程序的根目录

这里改成我们刚才写的cmd(bat)文件

然后继续向前.按照你的喜好来改设置

最后到这里的时候

我们还要改小小的地方..不然的话..

1.[Files]里面

Source: "E:\JAVA\AutoCheckOut\dist\lib\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

这一行 可以看到吧lib目录加到根目录区了..所以要改一下

Source: "E:\JAVA\AutoCheckOut\dist\lib\*"; DestDir: "{app}\lib\"; Flags: ignoreversion recursesubdirs createallsubdirs

2.[Icons]里面

Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"

需要多加一行

Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}";WorkingDir: "{app}"

加这行是为了让cmd运行时有正常的工作目录

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

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

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

第2步 : 选择“JAR in EXE mode” 就是选择已经有制作好的jar文件。

第3步 : 上面是项目名称,可随便填写,下面一个写出想要将打包后的exe文件输出的目录的是“桌面\project\”。

第4步 : 由于演示程序是图形的,所以选第一个,如果程序是控制台的,则选择第二个,Executable name写将要生成的.exe文件的名字,Icon File可以选择生成文件的图标。

第5步 : 先别管上面的,先在下面单击绿色的“+”号,在弹出的窗口中点Archive,然后找到起初已经做好的 CAMP_fat.jar(详见1.3)文件,"OK"后返回,在下面的Class Path里就出现jar文件路径后,再在上面Main Class栏内点击找到main所在的类。

第6步 : 系统的JRE版本,一般是填个1.3,下面填1.6在这里单击advanced options,选择search sequence。选这个就是因为要把JDK环境也打包进来,好让程序能跨平台使用。首先要从系统的JDK下的JRE目录copy到.exe文件的输出目录下“桌面\project\JRE”,然后回到exe4j中在弹出窗口删除列表中的所有项。是三项,一个注册表的,一个JAVA环境变量的,一个JDK环境变量的,都不要。然后单击绿“+”,选择directory并选择JRE的根目录,是“桌面\project\JRE”就是 copy后的目录,选完后exe4j弹出窗口中的Directory里会显示“.\JRE”。点OK关闭该窗口,返回exe4j的主窗口,就可以看到刚加的路径。再从主窗口左侧窗口中单击advanced options,并选择preferred VM,在弹出的窗口中选择client hostspot VM,单击next按钮继续。

第7、8步 : 是一些个性设置默认即可。

第9步 : 编译

第10步 : 点那个“Click Here to Start the Application”按钮就可以看到程序运行效果了,然后再点”Seave as”保存一个exe4j生成的一个文件,随便存哪里都行,和.exe程序无关。

关于java打包文件和java打包文件夹并下载的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-29,除非注明,否则均为首码项目网原创文章,转载请注明出处。