Java 如何使用包含某些文件的 ant 构建创建 EAR 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1267300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I create an EAR file with an ant build including certain files?
提问by user149100
I'm using eclipse to build an ear file using ant. I'm using oc4j, and I want to make sure that orion-application.xml is included in the build. What I'm currently using but does not work is:
我正在使用 eclipse 使用 ant 构建一个 ear 文件。我正在使用 oc4j,并且我想确保构建中包含 orion-application.xml。我目前正在使用但不起作用的是:
<target name="ear" depends=""> <echo>Building the ear file</echo> <copy todir="${build.dir}/META-INF"> <fileset dir="${conf.dir}" includes="orion-application.xml"/> </copy> <ear destfile="${dist.dir}/${ant.project.name}.ear" appxml="${conf.dir}/application.xml"> <fileset dir="${dist.dir}" includes="*.jar,*.war"/> </ear> </target>
What is the right way to add this to the ear?
将此添加到耳朵的正确方法是什么?
采纳答案by ChssPly76
Everything that should go into META-INF
folder should be specified via nested <metainf>
fileset:
应该META-INF
通过嵌套<metainf>
文件集指定应该进入文件夹的所有内容:
<ear destfile="${dist.dir}/${ant.project.name}.ear"
appxml="${conf.dir}/application.xml">
<metainf dir="${build.dir/META-INF}"/>
<fileset dir="${dist.dir}" includes="*.jar,*.war"/>
</ear>
回答by SmartCoder
First, build a war using this;
首先,使用它构建战争;
http://ant.apache.org/manual/Tasks/war.html
http://ant.apache.org/manual/Tasks/war.html
than an EAR in the same Ant task.
比同一个 Ant 任务中的 EAR。
http://ant.apache.org/manual/Tasks/ear.html
http://ant.apache.org/manual/Tasks/ear.html
Put this in your java project directory structure:
把它放在你的java项目目录结构中:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="test_ear" name="myProject">
<property name="build.dir" value="WebContent"/>
<target name="test_ear">
<war destfile="C:/projects/test1.war" needxmlfile='false'>
<fileset dir="${build.dir}" excludes="*build*.xml"/>
</war>
<ear destfile="C:/projects/test1EAR.ear" appxml="WebContent/META-INF/application.xml">
<fileset dir="C:/projects/" includes="*.jar,*.war"/>
</ear>
</target>
</project>
回答by sasah
Try this code:
试试这个代码:
<ear destfile="deploy/iapp.ear"
appxml="workspace/appEAR/EarContent/META-INF/application.xml">
<fileset file="workspace/appEJB/appEJB.jar" />
<fileset file="workspace/appWAR/appWAR.war" />
<zipfileset file="workspace/appLIB/appLIB.jar"
prefix="APP-INF/lib" />
<zipfileset dir="lib/fop" includes="*.jar" prefix="APP-INF/lib" />
<zipfileset dir="lib/poi" includes="*.jar" prefix="APP-INF/lib" />
<zipfileset dir="lib/gxt" includes="*.jar" prefix="APP-INF/lib" />
<metainf dir="workspace/appEAR/EarContent/META-INF">
<exclude name="**/application.xml" />
<exclude name="**/MANIFEST.MF" />
</metainf>
<manifest>
<attribute name="Weblogic-Application-Version"
value="${deploy.revision}" />
</manifest>
</ear>