繁体   English   中英

如何在我的构建中将导入的jar文件添加到eclipse中的web-inf / lib?

[英]How can I add imported jar files to web-inf/lib in eclipse for my build?

我理解与此有关的问题已得到解答,但我没有遇到在我的搜索中回答的这个特定问题。

我一直在尝试将我的导入JAR文件包含在我的构建(如下所示)的spring应用程序中,但我所做的任何事情都不是解决方案。 我在使用Tomcat和Ant在Eclipse中构建时收到'package not exists'错误,因为它无法在web-inf / lib文件夹中找到JAR文件(显然)。 Eclipse不允许我将文件从Referenced Library实用程序库中删除并拖动到任何所需的文件夹。 当我尝试配置构建路径时,我添加了外部JAR,文件所在的目录路径显示在库选项卡中的JAR旁边。 发布/导出依赖项设置为WEB-INF / lib文件夹我读过将所有JAR文件直接添加到Tomcat / lib文件夹(不应该这样做)可以解决问题,但对我来说情况并非如此。 我为JAR设置了/ WEB-INF / lib的部署程序集路径,没有运气。 我试过重启Eclipse,没有运气。 我创建了一个新的动态Web项目,没有运气。 我解压缩了war文件,没有找到JAR文件,这是预期的。 我相信我的环境变量是正确添加的

自从我使用Eclipse和Spring应用程序已经好几年了,所以我希望我错过了一个重要的步骤。

注意:这是一个Spring教程,我一直在努力让我重新站起来。 Eclipse版本4.3.0 Tomcat版本6 Ant版本1.8.4 - 作为Eclipse下载的插件包含在内

任何帮助将不胜感激,因为我会喜欢再次使用Web应用程序。

<project name="springapp1" basedir="." default="usage">
<property file="build.properties"/>

<property name="lib.dir" value="C:/Eclipse/Tomcat/lib"/>
<property name="webapps.dir" value="C:/Eclipse/Tomcat/webapps"/>

<property name="src.dir" value="src"/>
<property name="web.dir" value="WebContent"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="springapp1"/>

<path id="master-classpath">
    <fileset dir="${web.dir}/WEB-INF/lib">
        <include name="*.jar"/>
    </fileset>
    <!-- We need the servlet API classes: -->
    <!--  * for Tomcat 5/6 use servlet-api.jar -->
    <!--  * for other app servers - check the docs -->

    <!--<fileset dir="${appserver.lib}">-->
    <fileset dir="${lib.dir}">
        <include name="servlet*.jar"/>
    </fileset>
    <pathelement path="${build.dir}"/>
</path>

<target name="usage">
    <echo message=""/>
    <echo message="${name} build file"/>
    <echo message="-----------------------------------"/>
    <echo message=""/>
    <echo message="Available targets are:"/>
    <echo message=""/>
    <echo message="build     --> Build the application"/>
    <echo message="deploy    --> Deploy application as directory"/>
    <echo message="deploywar --> Deploy application as a WAR file"/>
    <echo message="install   --> Install application in Tomcat"/>
    <echo message="reload    --> Reload application in Tomcat"/>
    <echo message="start     --> Start Tomcat application"/>
    <echo message="stop      --> Stop Tomcat application"/>
    <echo message="list      --> List Tomcat applications"/>
    <echo message=""/>
</target>

<target name="build" description="Compile main source tree java files">
    <mkdir dir="${build.dir}"/>
    <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
           deprecation="false" optimize="false" failonerror="true">
        <src path="${src.dir}"/>
        <classpath refid="master-classpath"/>
    </javac>
</target>

<target name="deploy" depends="build" description="Deploy application">
    <copy todir="${webapps.dir}/${name}" preservelastmodified="true">
        <fileset dir="${web.dir}">
            <include name="**/*.*"/>
        </fileset>
    </copy>
    <echo message="Deploy Completed."/>
</target>

<target name="deploywar" depends="build" description="Deploy application as a WAR file">
    <war destfile="${name}.war"
         webxml="${web.dir}/WEB-INF/web.xml">
        <fileset dir="${web.dir}">
            <include name="**/*.*"/>
        </fileset>
    </war>
    <copy todir="${webapps.dir}" preservelastmodified="true">
        <fileset dir=".">
            <include name="*.war"/>
        </fileset>
    </copy>
</target>

<path id="catalina-ant-classpath">
    <!-- We need the Catalina jars for Tomcat -->
    <!--  * for other app servers - check the docs -->
    <fileset dir="C:/Eclipse/Tomcat/lib">
        <include name="catalina-ant.jar"/>
    </fileset>
</path>

<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>

<target name="install" description="Install application in Tomcat">
    <install url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"
             war="${name}"/>
</target>

<target name="reload" description="Reload application in Tomcat">
    <reload url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"/>
</target>

<target name="start" description="Start Tomcat application">
    <start url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"/>
</target>

<target name="stop" description="Stop Tomcat application">
    <stop url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"/>
</target>

<target name="list" description="List Tomcat applications">
    <list url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"/>
</target>

删除需要在Eclipse项目的WebContent/WEB-INF/lib产品下的已部署webapp的类路径中的jar(在WEB-INF/lib )。 这就是你需要做的。

如果已将它们添加到项目的构建路径中,则从那里删除它们: WebContent/WEB-INF/lib下的所有内容都会自动添加到构建路径中。

尝试将所有jar用于类路径

<fileset dir="${lib.dir}">
    <include name="*.jar"/>
</fileset>

暂无
暂无

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

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