简体   繁体   English

在WAR文件的WEB-INF文件夹下打包Java类

[英]Package Java classes under WEB-INF folder in WAR file

I am using the following to package war file in ANT script 我正在使用以下内容将战争文件打包在ANT脚本中

<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. 我想实现的是打包打包war时,我想将java类与lib文件夹一起放在WEB-INF文件夹下。

How can I do this? 我怎样才能做到这一点?

The WAR Task documentation says (in part) The nested classes element specifies a FileSet. WAR Task文档说(部分) ,嵌套classes元素指定一个FileSet。 All files included in this fileset will end up in the WEB-INF/classes directory of the war file. 该文件集中包含的所有文件都将最终在war文件的WEB-INF / classes目录中。 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. 第一个JAR你的类和掖那jarwar文件之后。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gradle WAR 与 WEB-INF/classes 下的编译类 - Gradle WAR with compiled classes under WEB-INF/classes 如何在Java类中的WEB-INF文件夹下访问文件 - How to access a file under WEB-INF folder in java class 当类在JBoss 6 WAR WEB-INF / classes文件夹中时,NoClassDefFoundError - NoClassDefFoundError when class is in JBoss 6 WAR WEB-INF/classes folder 如何将.class下的web-inf / classs打包为jar并将其放入web-inf / lib目录 - how to package the .class under the web-inf/classes as a jar and put it to the web-inf/lib dir 我们的 war/WEB-INF 文件夹中资源的文件路径? - File path to resource in our war/WEB-INF folder? 如何在战争的WEB-INF文件夹中包含属性文件 - How to include a property file in WEB-INF folder of war Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder? - Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder? 如何将inputstream转换为java中tomcat中web-inf文件夹下的配置文件? - how to get the inputstream to configuration file lying under web-inf folder in tomcat in java? Maven:将 war/web-inf/classes 中的类作为 jar 添加到 war/web-inf/lib - Maven: Adding classes from war/web-inf/classes as a jar to war/web-inf/lib 在Eclipse中访问Java项目中WEB-INF下的ftl文件 - Accessing an ftl file under WEB-INF in a Java Project in eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM