您的位置:程序门 -> java -> j2ee / ejb / jms



向java高手索要build.xml,100分赠


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


向java高手索要build.xml,100分赠[已结贴,结贴人:woailiyanrui]
发表于:2007-09-12 13:43:13 楼主
我想要一个能在eclipse中编译项目java文件为class文件的build.xml
请问有高手能为我写一个么
有100分相送,我给您跪下了啊
发表于:2007-09-12 14:00:081楼 得分:0
我原来的项目是在jbuilder中编译过的
直接拿到eclipse中会不会编译错误呢
这个也有分
发表于:2007-09-12 14:02:192楼 得分:1
jf
发表于:2007-09-12 14:38:383楼 得分:1
我有,怎么给你,而且很详细,该文件会编译成class并且能打包ear
发表于:2007-09-12 14:41:164楼 得分:4
直接到apache的网站上看看,上面有个现成的例子
http://ant.apache.org/manual/index.html
发表于:2007-09-12 14:43:375楼 得分:0
我的邮箱是wzysnb@163.com
发过来吧谢谢
我还有个帖子地址是
发完后你上那个说句话我把那上的分也给你
发表于:2007-09-12 15:07:426楼 得分:0

1   -   always   provide   shell   launchers   for   ant.   a   standalone   build.xml   is   simply   too   demanding   for   developers,   who   are   used   to   luxuries   like   build.bat   and   build.sh.   nothing   says   'we   care   about   your   platform '   like   shell   script   launchers.  

2   -   while   you 're   writing   those   launchers,   make   sure   you   provide   specialized   ones   so   users   can   very   easy   call   various   build   targets.   build.sh   looks   naked   and   sad   without   its   childhood   friends,   make.sh,   compile.sh,   docs.sh,   and   run.sh.  

3   -   never   place   your   build.xml   file   in   your   top   level   directory.   the   deeper   in   it   is,   the   more   likely   it   is   that   people   will   actually   look   at   your   stuff   in   a   hopeless   effort   to   find   said   file.  

4   -   never   allow   for   people   to   customize   the   build   process.   sourcing   an   external   properties   file   is   just   cause   for   confusion   and   trauma.  

5   -   if   you   do   want   customization,   then   force   users   to   define   env   vars.   since   every   user 's   environment   is   unique   and   specific,   why   not   demand   and   expect   them   to   define   12   *_home   type   variables   first?   that   way   when   they   do   get   the   build   going,   they 'll   feel   it 's   like   a   personal   customized   version   that   is   tailored   for   their   own   needs   and   nobody   else 's.  

6   -   never   rely   on   -projecthelp.   the   default   ant   target   should   do   nothing   but   spit   out   a   few   pages   of   useless   info   explaining   all   the   available   targets.   yes,   ant   does   allow   for   this   via   the   -projecthelp   switch,   but   that   assumes   users   know   when   they   need   help.   it   is   obvious   to   you,   almighty   developer,   that   unless   they   explicitly   ask   for   something   else,   they   want   help.  

7   -   your   default   target   should   try   to   surprise   and   amuse   users.   why   have   a   target   that   just   builds   your   project   when   instead   you   can   have   it   build   a   whole   distribution?   sure,   builders   are   those   who   might   well   poke   about   the   source   and   want   quick   builds   via   ant,   but   screw   them.   a   whole   distribution   just   looks   so   much   more   professional.  

8   -   ask   users   to   prove   their   loyalty   and   dedication   to   your   cause   by   demanding   they   add   jar   files   to   ant_home/lib.   for   extra   points,   do   not   tell   them   what   these   jar   files   are.   it   can   be   a   test   of   the   true   faithful   to   see   if   they   can   figure   it   out   from   an   ant   stacktrace   and   find   out   what   jar   to   download   from   where.  

9   -   never   ship   dependent   jars.   as   any   true   maven   asshat   knows,   jars   should   be   delivered   over   the   network   from   a   central   repository.   this   way   you   can   automatically   weed   out   those   pesky   enterprise   users   behind   restrictive   firewalls   who   are   in   all   likelihood   violently   opposed   to   opensores   anyway.   make   liberal   use   of   the   get   task,   it 's   there   for   a   reason   you   know.  

10   -   ensure   a   fresh   start!   every   target   should   depend   on   the   clean   target.   this   way   you   can   be   sure   that   the   user   will   not   have   any   problems   with   left   over   cruft   from   an   old   build.   sure,   their   build   rate   will   slow   down   by   a   few   orders   of   magnitude,   but   it 's   better   to   be   safe   than   sorry.  

11   -   build.xml   should   be   your   gateway   to   everything.   don 't   be   fooled   by   its   name,   you   can   and   should   use   it   to   run   your   apps   too.   why   bother   with   pesky   manifests   and   cumbersome   jar   files?   they 're   from   the   evil   un-free   empire   of   sun,   so   you   must   shun   them.   instead,   make   liberal   use   of   the   java   task   in   ant.   real   build.xml   love   will   shine   through   the   next   time   you   type   ant   run.  

12   -   consolidation   is   for   the   weak.   a   single   buildfile   basically   screams   out   'i 'm   a   girl   and   like   bunnies   and   wear   pink   fluffy   dresses '.   if   you 're   going   for   a   more   manly   effect,   then   split   your   build.xml   files   into   as   many   pieces   as   possible.   extra   points   for   bragging   about   reusability   and   employing   cunning   task   obfuscation.   the   casual   user   must   never   be   able   to   figure   out   what   is   actually   going   on,   or   they 'll   get   funny   ideas   that   they   could   have   done   it   themselves.  


1   -   always   provide   shell   launchers   for   ant.   a   standalone   build.xml   is   simply   too   demanding   for   developers,   who   are   used   to   luxuries   like   build.bat   and   build.sh.   nothing   says   'we   care   about   your   platform '   like   shell   script   launchers.  

2   -   while   you 're   writing   those   launchers,   make   sure   you   provide   specialized   ones   so   users   can   very   easy   call   various   build   targets.   build.sh   looks   naked   and   sad   without   its   childhood   friends,   make.sh,   compile.sh,   docs.sh,   and   run.sh.  

3   -   never   place   your   build.xml   file   in   your   top   level   directory.   the   deeper   in   it   is,   the   more   likely   it   is   that   people   will   actually   look   at   your   stuff   in   a   hopeless   effort   to   find   said   file.  

4   -   never   allow   for   people   to   customize   the   build   process.   sourcing   an   external   properties   file   is   just   cause   for   confusion   and   trauma.  

5   -   if   you   do   want   customization,   then   force   users   to   define   env   vars.   since   every   user 's   environment   is   unique   and   specific,   why   not   demand   and   expect   them   to   define   12   *_home   type   variables   first?   that   way   when   they   do   get   the   build   going,   they 'll   feel   it 's   like   a   personal   customized   version   that   is   tailored   for   their   own   needs   and   nobody   else 's.  

6   -   never   rely   on   -projecthelp.   the   default   ant   target   should   do   nothing   but   spit   out   a   few   pages   of   useless   info   explaining   all   the   available   targets.   yes,   ant   does   allow   for   this   via   the   -projecthelp   switch,   but   that   assumes   users   know   when   they   need   help.   it   is   obvious   to   you,   almighty   developer,   that   unless   they   explicitly   ask   for   something   else,   they   want   help.  

7   -   your   default   target   should   try   to   surprise   and   amuse   users.   why   have   a   target   that   just   builds   your   project   when   instead   you   can   have   it   build   a   whole   distribution?   sure,   builders   are   those   who   might   well   poke   about   the   source   and   want   quick   builds   via   ant,   but   screw   them.   a   whole   distribution   just   looks   so   much   more   professional.  

8   -   ask   users   to   prove   their   loyalty   and   dedication   to   your   cause   by   demanding   they   add   jar   files   to   ant_home/lib.   for   extra   points,   do   not   tell   them   what   these   jar   files   are.   it   can   be   a   test   of   the   true   faithful   to   see   if   they   can   figure   it   out   from   an   ant   stacktrace   and   find   out   what   jar   to   download   from   where.  

9   -   never   ship   dependent   jars.   as   any   true   maven   asshat   knows,   jars   should   be   delivered   over   the   network   from   a   central   repository.   this   way   you   can   automatically   weed   out   those   pesky   enterprise   users   behind   restrictive   firewalls   who   are   in   all   likelihood   violently   opposed   to   opensores   anyway.   make   liberal   use   of   the   get   task,   it 's   there   for   a   reason   you   know.  

10   -   ensure   a   fresh   start!   every   target   should   depend   on   the   clean   target.   this   way   you   can   be   sure   that   the   user   will   not   have   any   problems   with   left   over   cruft   from   an   old   build.   sure,   their   build   rate   will   slow   down   by   a   few   orders   of   magnitude,   but   it 's   better   to   be   safe   than   sorry.  

11   -   build.xml   should   be   your   gateway   to   everything.   don 't   be   fooled   by   its   name,   you   can   and   should   use   it   to   run   your   apps   too.   why   bother   with   pesky   manifests   and   cumbersome   jar   files?   they 're   from   the   evil   un-free   empire   of   sun,   so   you   must   shun   them.   instead,   make   liberal   use   of   the   java   task   in   ant.   real   build.xml   love   will   shine   through   the   next   time   you   type   ant   run.  

12   -   consolidation   is   for   the   weak.   a   single   buildfile   basically   screams   out   'i 'm   a   girl   and   like   bunnies   and   wear   pink   fluffy   dresses '.   if   you 're   going   for   a   more   manly   effect,   then   split   your   build.xml   files   into   as   many   pieces   as   possible.   extra   points   for   bragging   about   reusability   and   employing   cunning   task   obfuscation.   the   casual   user   must   never   be   able   to   figure   out   what   is   actually   going   on,   or   they 'll   get   funny   ideas   that   they   could   have   done   it   themselves.  
谁能帮我翻译
我的分都给他
价值200分
发表于:2007-09-12 15:09:037楼 得分:6
可以下在appfuse,看看人家的build.xml是怎么写的
发表于:2007-09-12 15:23:118楼 得分:0
我在地上打滚耍赖了啊
都不告诉我啊
发表于:2007-09-12 16:00:409楼 得分:1
这些东西   不都是会自动生成的么   ~!     我怎么从来没遇到过这种事情~!
发表于:2007-09-12 16:21:2810楼 得分:0
我在将项目从jbuilder导入到eclipse的过程中重新构建了一个java   web   project.
所以要写builder.xml
这回明白了吧
发表于:2007-09-12 16:28:3011楼 得分:1
web项目要打包干吗?
发表于:2007-09-12 16:31:0812楼 得分:21
<project   name= "blank "   basedir= "../ "   default= "all ">


        <!--   local   system   paths   -->
        <property   name= "servlet.jar "   value= "/javasoft/lib/jdbc2_0-stdext.jar "/>
        <property   name= "jdbc20ext.jar "   value= "/javasoft/lib/servlet.jar "/>
                <!--   note:   if   "dist "   target   is   used,   a   local
                          "projects/lib "   directory   will   be   utilized   or   created   -->
        <property   name= "distpath.project "   value= "/projects/lib "/>


        <!--   project   settings   -->
        <property   name= "project.title "   value= "jakarta   struts   blank   "/>
        <property   name= "project.distname "   value= "blank "/>
        <property   name= "project.version "   value= "1.1 "/>


        <!--   path   settings   -->
        <property   name= "doc.path "   value= "./doc/api "/>
        <property   name= "doc.src "   value= "./src/java "/>


        <!--   classpath   for   struts   1.1   -->
        <path   id= "compile.classpath ">
                <pathelement   path   = "lib/commons-beanutils.jar "/>
                <pathelement   path   = "lib/commons-digester.jar "/>
                <pathelement   path   = "lib/struts.jar "/>
                <pathelement   path   = "classes "/>
                <pathelement   path   = "${classpath} "/>
        </path>


        <!--   check   timestamp   on   files   -->
        <target   name= "prepare ">
                <tstamp/>
        </target>


        <!--   copy   any   resource   or   configuration   files   -->
        <target   name= "resources ">
                <copy   todir= "classes "   includeemptydirs= "no ">
                        <fileset   dir= "src/java ">
                        <patternset>
                                <include   name= "**/*.conf "/>
                                <include   name= "**/*.properties "/>
                                <include   name= "**/*.xml "/>
                        </patternset>
                        </fileset>
                </copy>
        </target>


        <!--   normal   build   of   application   -->
        <target   name= "compile "   depends= "prepare,resources ">
                <javac   srcdir= "src "   destdir= "classes ">
                        <classpath   refid= "compile.classpath "/>
                </javac>
        </target>


        <!--   remove   classes   directory   for   clean   build   -->
        <target   name= "clean "
            description= "prepare   for   clean   build ">
            <delete   dir= "classes "/>
            <mkdir     dir= "classes "/>
        </target>


        <!--   build   javadoc   documentation   -->
        <target   name= "javadoc "
          description= "generate   javadoc   api   docs ">
                <delete   dir= "./doc/api "/>
                <mkdir   dir= "./doc/api "/>
                <javadoc   sourcepath= "./src/java "
                        destdir= "./doc/api "
                        classpath= "${servlet.jar}:${jdbc20ext.jar} "
                        packagenames= "* "
                        author= "true "
                        private= "true "
                        version= "true "
                        windowtitle= "${project.title}   api   documentation "
                        doctitle= "&lt;h1&gt;${project.title}   documentation   (version   ${project.version})&lt;/h1&gt; "
                        bottom= "copyright   &#169;   2002 ">
                        <classpath   refid= "compile.classpath "/>
                </javadoc>
        </target>


        <!--   build   entire   project   -->
        <target   name= "project "   depends= "clean,prepare,compile,javadoc "/>


        <!--   create   binary   distribution   -->
        <target   name= "dist "
                description= "create   binary   distribution ">

            <mkdir
                dir= "${distpath.project} "/>
            <jar
                jarfile= "${distpath.project}/${project.distname}.jar "
                basedir= "./classes "/>
            <copy
                file= "${distpath.project}/${project.distname}.jar "
                todir= "${distpath.project} "/>

            <war
                basedir= "../ "
                warfile= "${distpath.project}/${project.distname}.war "
                webxml= "web.xml ">
                <exclude   name= "${distpath.project}/${project.distname}.war "/>
              </war>

        </target>


        <!--   build   project   and   create   distribution-->
        <target   name= "all "   depends= "project,dist "/>

</project>
发表于:2007-09-12 16:32:0213楼 得分:0
其实不是打包
我只是想编译一下   看看能否build   successful
明白了吧
发表于:2007-09-12 16:34:2014楼 得分:0
skychen1900()   高手你好
可以把我要改动的地方加上注释么
谢谢你了
我为你裸跪
发表于:2007-09-12 16:40:2015楼 得分:65
<?xml   version= "1.0 "   encoding= "utf-8 "?>

<project   basedir= ". "   default= "usage "   name= "myproject ">

<property   file= "build.properties "   />

<property   name= "src.dir "   value= "${basedir}/src "   />
<property   name= "conf.dir "   value= "${basedir}/conf "   />
<property   name= "lib.dir "   value= "${basedir}/lib "   />
<property   name= "web.dir "   value= "${basedir}/web "   />
<property   name= "build.dir "   value= "${web.dir}/web-inf/classes "   />
<property   name= "target.dir "   value= "${basedir}/target "   />
<property   name= "test.dir "   value= "${basedir}/test "   />
<property   name= "test.data "   value= "${target.dir}/test/data "   />
<property   name= "test.build "   value= "${target.dir}/test/classes "   />
<property   name= "functional_test.data "   value= "${target.dir}/test/fun_data "   />
<property   name= "release.warfile "   value= "${target.dir}/war/${ant.project.name}.war "   />

<taskdef   resource= "net/sf/antcontrib/antcontrib.properties "   classpath= "${lib.dir}/ant/ant-contrib.jar "   />

<target   name= "usage ">
<echo   message= "${ant.project.name}   build   文件 "   />
<echo   message= "------------------------------------------------------ "   />
<echo   message= "可选target: "   />
<echo   message= " "   />
<echo   message= "compile               --&gt;   编译java文件并复制资源文件 "   />
<echo   message= "war                       --&gt;   生成项目war文件 "   />
<echo   message= "test                     --&gt;   运行junit单元测试 "   />
<echo   message= "clean                   --&gt;   清空项目 "   />
<input   message= "请选择一个target "   validargs= "compile,war,test,clean "   addproperty= "ant.task "   />
<antcall   target= "${ant.task} "   />
</target>

<!--   ===================================
  初始化项目,建立目录并更新项目的依赖jar.
====================================   -->
<target   name= "init ">
<mkdir   dir= "${build.dir} "   />
<mkdir   dir= "${test.build} "   />
<mkdir   dir= "${test.data} "/>
<mkdir   dir= "${functional_test.data} "/>
</target>

<!--   ===================================
  定义class   path
====================================   -->
<path   id= "compile.classpath ">
<fileset   dir= "${web.dir}/web-inf/lib "   includes= "*.jar "   />
<fileset   dir= "lib "   includes= "**/*.jar "   />
</path>

<path   id= "test.classpath ">
<path   refid= "compile.classpath "   />
<path   location= "${build.dir} "   />
</path>

<!--   定义编译选项   -->
<property   name= "compiler.args "   value= "-encoding   utf-8 "   />

<patternset   id= "compiler.conf ">
<exclude   name= "**/?*.java "   />
</patternset>

<!--   检查环境   -->
<target   name= "check-env ">
<!--   检查jdk版本为5.0   -->
<fail   message= "must   set   the   java_home   to   jdk5.0 ">
<condition>
<not>
<equals   arg1= "${ant.java.version} "   arg2= "1.5 "   />
</not>
</condition>
</fail>
</target>

<!--   ===================================
  编译java文件并复制资源文件
====================================   -->
<target   name= "compile "   depends= "check-env,init,i18n ">
<if>
<available   file= "${src.dir} "   />
<then>
<javac   destdir= "${build.dir} "   debug= "true ">
<compilerarg   line= "${compiler.args} "   />
<src   path= "${src.dir} "   />
<classpath   refid= "compile.classpath "   />
</javac>
</then>
</if>

<copy_resource   conf.dir= "${src.dir} "   build.dir= "${build.dir} "   />
<copy_resource   conf.dir= "${conf.dir} "   build.dir= "${build.dir} "   />

<!--   编译单元测试的java文件   -->
<if>
<available   file= "${test.dir} "   />
<then>
<javac   destdir= "${test.build} "   debug= "true ">
<compilerarg   line= "${compiler.args} "   />
<src   path= "${test.dir} "   />
<classpath   refid= "test.classpath "   />
</javac>

</then>
</if>

<copy_resource   conf.dir= "${test.dir} "   build.dir= "${test.build} "   />

</target>

<macrodef   name= "copy_resource ">
<attribute   name= "build.dir "   />
<attribute   name= "conf.dir "   />
<sequential>
<!--   复制resource下的资源文件到classes目录   -->
<if>
<available   file= "@{conf.dir} "   />
<then>
<copy   todir= "@{build.dir} ">
<fileset   dir= "@{conf.dir} ">
<patternset   refid= "compiler.conf "   />
<exclude   name= "**/.bak "   />
</fileset>
</copy>
</then>
</if>
</sequential>
</macrodef>

<!--   ===================================
  中文i18n文件进行utf-8转换
====================================   -->
<target   name= "i18n ">
<if>
<available   file= "${conf.dir}/i18n/cn "   />
<then>
<native2ascii   src= "${conf.dir}/i18n/cn "   dest= "${conf.dir}/i18n "   encoding= "utf-8 "   />
</then>
</if>
</target>

<!--   ===================================
  生成war文件
====================================   -->
<target   name= "war "   depends= "compile ">
<mkdir   dir= "${target.dir}/war/ "   />

<tstamp>
<format   property= "datestamp "   pattern= "yyyy-mm-dd "   />
</tstamp>
<war   destfile= "${release.warfile} "   webxml= "${web.dir}/web-inf/web.xml "   basedir= "${web.dir} "   excludes= "**/web.xml ">
<manifest>
<section   name= "shared ">
<attribute   name= "date "   value= "${datestamp} "   />
</section>

<section   name= "copyright ">
<attribute   name= "copy "   value= "(c)   ${ant.project.name}   2007 "   />
</section>
</manifest>
</war>
</target>

<!--   =========================================
  运行junit测试
=========================================   -->
<property   name= "test.report "   value= "${target.dir}/test/reports "   />

<target   name= "test "   depends= "compile ">

<!--   检查   junit.jar   -->
<available   classname= "junit.framework.testcase "   property= "junit.present "   />
<fail   unless= "junit.present "   message= "please   copy   lib/junit-3.8.1.jar   into   env.ant_home/lib   or   class   path "   />
<!--   清除上次的data数据   -->
<delete   dir= "${test.data} "   />
<mkdir   dir= "${test.data} "   />
<!--   执行测试   -->
<junit   printsummary= "yes "   fork= "true "   errorproperty= "test.failed "   failureproperty= "test.failed ">
<classpath>
<path   refid= "test.classpath "   />
<path   location= "${test.build} "   />
</classpath>
<formatter   type= "xml "   />
<formatter   type= "brief "   usefile= "false "   />

<!--   执行单个或批量的test   case。
如果在命令行有定义testcase,
如:   ant   -dtestcase=com.gresoft.sanitation.test.mytestcase  
则执行单个test   case.   -->
<test   name= "${testcase} "   if= "testcase "   />

<batchtest   todir= "${test.data} ">
<fileset   dir= "${test.build} ">
<exclude   name= "**/functional/**/*test.class "   />
<include   name= "**/*test.class "   />
</fileset>
</batchtest>
</junit>
<if>
<istrue   value= "${test.failed} "   />
<then>
<test-report   report.dir= "${test.report} "   data.dir= "${test.data} "   />
<fail> unit   tests   失败.   请于${test.report}目录观看错误信息报表. </fail>
</then>
</if>
</target>

<!--   生成junit测试结果报表   -->
<macrodef   name= "test-report ">
<attribute   name= "data.dir "   />
<attribute   name= "report.dir "   />
<sequential>
<mkdir   dir= "@{report.dir} "   />
<junitreport   todir= "@{report.dir} ">
<fileset   dir= "@{data.dir} ">
<include   name= "test-*.xml "   />
</fileset>
<report   format= "frames "   todir= "@{report.dir} "   />
</junitreport>
</sequential>
</macrodef>

<target   name= "test-all "   depends= "test,fun-test "   />

<target   name= "deploy "   depends= "compile "   description= "deploy   application ">
<copy   todir= "${deploy.path}/${ant.project.name} "   preservelastmodified= "true ">
<fileset   dir= "${web.dir} ">
<include   name= "**/*.* "   />
</fileset>
</copy>
</target>

<target   name= "deploywar "   depends= "war "   description= "deploy   application   as   a   war   file ">
<copy   todir= "${deploy.path} "   preservelastmodified= "true ">
<fileset   dir= "${target.dir}/war ">
<include   name= "*.war "   />
</fileset>
</copy>
</target>

<!--   ===================================
  清理项目,删除classes目录
====================================   -->
<target   name= "clean ">
<delete   dir= "${build.dir} "   />
<delete   dir= "${test.build} "   />
</target>

</project>
发表于:2007-09-12 17:20:4616楼 得分:0
http://community.csdn.net/expert/topic/5754/5754688.xml?temp=.1030695
这上也有100分
发表于:2007-09-12 17:27:2417楼 得分:0
刚才发错了
是这个地址
http://community.csdn.net/expert/topic/5754/5754688.xml?temp=.2925379


快速检索

最新资讯
热门点击