java代码如何打包(java编写的程序怎么打包发布)

本篇文章给大家谈谈java代码如何打包,以及java编写的程序怎么打包发布对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

Eclipse如何将Java项目打包成jar包?

如果自己的java project中需要引用额外的jar包作为资源文件,那么需要自定义配置文件MANIFEST.MF ,例如:\x0d\x0aManifest-Version: 1.0\x0d\x0aClass-Path: lib\crimson.jar lib\jbcl.jar lib\junit.jar lib\log4j-1.2.13.jar lib\mysql-connector-java-3.1.13-bin.jar\x0d\x0aMain-Class: src.YourMainClassName\x0d\x0a其中的Class-Path就指定了外来jar包的位置。请注意假设我们的项目打包后为project.jar,那么按照上面的定义,应该在 project.jar的同层目录下建立一个lib文件夹,并将相关的jar包放在里面。否则将会出现Exception in thread "main" java.lang.NoClassDefFoundError的错误。\x0d\x0a如果想在所导出的jar包中包含第三方jar包,可以如下操作:\x0d\x0a1.在工程目录下放入第三方jar包\x0d\x0a2.Class-Path: name.jar\x0d\x0a上诉两个步骤就可以成功导出引用了jar包的java工程,并将第三方jar包放在导出的工程中\x0d\x0a注意:如果在Class-Path 中引入比较多的jar包,不要写成一行,不然会报:java.io.IOException : line too long ,需要分多行写,第二行以及下面的第三行、第四行写的时候需要在前面空两格(敲两下空格键)即可\x0d\x0a最后介绍一下使用Eclipse制作jar包的过程吧:\x0d\x0a1. 首先在Eclipse中打开项目, 右键点击项目,选择“Export”;\x0d\x0a2. 选择Java/JAR file,Next;\x0d\x0a3. Select the resources to export中可以选择你想要包含的项目文件夹,一些不必要的文件夹就无需放进去了,免得增大空间;\x0d\x0a这里有几个选项:\x0d\x0a* Export generated class files and resources 表示只导出生成的.class文件和其他资源文件\x0d\x0a* Export all output folders for checked projects 表示导出选中项目的所有文件夹\x0d\x0a* Export java source file and resouces 表示导出的jar包中将包含你的源代码*.java,如果你不想泄漏源代码,那么就不要选这项了\x0d\x0a* Export refactorings for checked projects 把一些重构的信息文件也包含进去\x0d\x0a在Select the export destination中选择导出的jar的路径,Next\x0d\x0a4. 下一页可以选择是否导出那些含有警告warning或者错误errors的*.class文件。一般不用理他,Next\x0d\x0a5. 下一个页面里可以对项目做一些配置。\x0d\x0a* Generate the manifest file是系统帮我们自动生成MANIFEST.MF文件,如果你的项目没有引用其他class-path,那可以选择这一项。\x0d\x0a* Use existing mainfest from workspace。这是可以选择我们自定义的.MF文件,格式如上所写。\x0d\x0a* Seal content。要封装整个jar或者指定的包packet\x0d\x0a* Main class。这里可以选择你的程序入口,将来打包出来的jar就是你这个入口类的执行结果。\x0d\x0a最后Finish 完成

java代码如何打包(java编写的程序怎么打包发布),java代码如何打包,信息,文章,源码,第1张

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如何打包

建议使用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源码打包成exe

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

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

2、选择Java选项,再选择Runnable JAR file选项,点击next按钮;

3、选择程序的主类,还有Main函数的类和输入要导出的位置,点击finish;

4、在电脑上,设置好Jar文件的打开方式(别默认用解压缩的工具打开就行),双击即可运行。

java代码如何打包的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java编写的程序怎么打包发布、java代码如何打包的信息别忘了在本站进行查找喔。

1、本网站名称:源码村资源网
2、本站永久网址:https://www.yuanmacun.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
源码村资源网 » java代码如何打包(java编写的程序怎么打包发布)

1 评论

您需要 登录账户 后才能发表评论

发表评论

欢迎 访客 发表评论