简体   繁体   中英

Package Java classes under WEB-INF folder in WAR file

I am using the following to package war file in ANT script

<target name="war" depends="compile">
    <war destfile="${deploy.dir}/vms_war.war" webxml="${web.dir}/WEB-INF/web.xml">
      <fileset dir="${classes.dir}">
        <include name="**/*.class"/>
        <exclude name="test/**/*.class"/>
      </fileset>
       <fileset dir="${src.dir}">
       <include name="**/*.xml"/>
      </fileset>
      <fileset dir="${web.dir}">
        <include name="**/*.jspx"/>
        <include name="**/*.jsp"/>
        <include name="**/*.html"/>                        
        <include name="WEB-INF/*.xml"/>
        <include name="WEB-INF/lib/*.*"/>
        <exclude name="**/web.xml"/>
      </fileset>
    </war>
  </target>

When war is packaged, the structure is as follows

--WEB-INF
  lib 
  web.xml
  faces-config.xml
--mypackageappname
     app
     test
     Login.class
     Authenticate.class
     ....

What I would like to achieve is when war is packaged, I would want to put java classes to be under WEB-INF folder along with lib folder.

How can I do this?

The WAR Task documentation says (in part) The nested classes element specifies a FileSet. All files included in this fileset will end up in the WEB-INF/classes directory of the war file. I think you wanted something like

<war destfile="${deploy.dir}/vms_war.war" webxml="${web.dir}/WEB-INF/web.xml">
  <classes dir="${classes.dir}" />
  <fileset dir="${src.dir}">
    <include name="**/*.xml"/>
  </fileset>
  <fileset dir="${web.dir}">
    <include name="**/*.jspx"/>
    <include name="**/*.jsp"/>
    <include name="**/*.html"/>                        
    <include name="WEB-INF/*.xml"/>
    <include name="WEB-INF/lib/*.*"/>
    <exclude name="**/web.xml"/>
  </fileset>
</war>

Jar up your classes first and tuck that jar into the war file afterward. Something like this:

<target name="war" depends="compile">
    <jar jarfile="${web.dir}/WEB-INF/lib/vms.jar">
      <fileset dir="${classes.dir}">
        <include name="**/*.class"/>
        <exclude name="test/**/*.class"/>
      </fileset>
    </jar>
    <war destfile="${deploy.dir}/vms_war.war" webxml="${web.dir}/WEB-INF/web.xml">
      <fileset dir="${src.dir}">
        <include name="**/*.xml"/>
      </fileset>
      <fileset dir="${web.dir}">
        <include name="**/*.jspx"/>
        <include name="**/*.jsp"/>
        <include name="**/*.html"/>                        
        <include name="WEB-INF/*.xml"/>
        <include name="WEB-INF/lib/*.*"/>
        <exclude name="**/web.xml"/>
      </fileset>
    </war>
  </target>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM