简体   繁体   English

在Eclipse中设置新项目

[英]Setting up new project in Eclipse

So I set up a new project into Eclipse and created a build.xml that creates a war file. 因此,我在Eclipse中建立了一个新项目,并创建了一个build.xml来创建war文件。 The problem that I am having is that the only files that are included in the war are what's in the WEB-INF. 我遇到的问题是战争中唯一包含的文件就是WEB-INF中的文件。 How do you include my web folder into the war? 您如何将我的网络文件夹包含在战争中?

  • Project 项目
    • src src
    • web 网络
    • WEB-INF 网络信息

(edited for correctness and clarity) (为确保正确性和清晰度而进行了编辑)

Assuming Project Setup as follows: 假设项目设置如下:

  • Project 项目
    • src (java source files) src(Java源文件)
    • web (web content) 网络(网络内容)
    • WEB-INF (with at least a web.xml inside) WEB-INF(内部至少包含一个web.xml)
    • build (build.xml is here) 构建(build.xml在这里)

Here's a quick ant script to war it up: 这是一个警告它的快速蚂蚁脚本:

<?xml version="1.0"?>
<project name="sample" basedir="../" default="war">

    <target name="compile">
        <delete dir="build/classes"/>
        <mkdir dir="build/classes"/>
        <javac srcdir="src" destdir="build/classes"/>
    </target>

    <target name="war" depends="compile">
        <war destfile="myWar.war" webxml="WEB-INF/web.xml">
            <fileset dir="web"/>
            <classes dir="build/classes"/>
            <webinf dir="WEB-INF"/>
        </war>
    </target>

</project>

See the Ant user manual for the war task for more information. 有关war任务的更多信息,请参见Ant用户手册。

Your WEB-INF should be below the web folder. 您的WEB-INF应该在web文件夹下面。 Classes should go in web/WEB-INF/classes. 类应该放在web / WEB-INF / classes中。

Build the finished layout and then use the WAR task to wrap it up. 构建完成的布局,然后使用WAR任务对其进行包装。

Since you are referring to a build.xml file, I'll assume you are using Ant (or Eclipse is using it for you.) If that is the case, you want to use the war Ant task and its includes attribute (or fileset nested task) to list your web directory for inclusion in the resulting war. 由于您引用的是build.xml文件,因此我假设您正在使用Ant(或者Eclipse正在为您使用它)。如果是这种情况,则要使用war Ant任务及其包含属性(或文件集)嵌套任务)以列出要包含在产生的战争中的Web目录。

http://ant.apache.org/manual/Tasks/war.html http://ant.apache.org/manual/Tasks/war.html

Assuming you are using an older Ant distribution that lacks the war task, use the jar task, which war inherits from. 假设您正在使用缺少war任务的较旧的Ant发行版,请使用war继承的jar任务。

I don't know what your build.xml looks like, but I would venture to guess it has a war or jar task. 我不知道您的build.xml是什么样子,但我敢冒险猜测它具有warjar任务。 Using its includes attribute, it should look something like this (this is from the top of my head, you might need to tweak it to compile for your specific situation): 使用其includes属性,它应该看起来像这样(这是从我的头开始的,您可能需要对其进行调整以针对您的特定情况进行编译):

<war destfile="your.war" webxml="src/metadata/your.xml">
  <fileset dir="src"/>
  <fileset dir="web"/>
  <classes dir="build/classes"/>
</war>

Without seeing your build.xml, it is impossible to tell if this suggestion is applicable or not, though. 但是,如果看不到build.xml,就无法确定该建议是否适用。

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

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