错误,包括ant脚本外部JAR [英] error while including external JARs in ant script

查看:105
本文介绍了错误,包括ant脚本外部JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在写一个Ant脚本的第一次尝试。这是我使用Spring一个简单的Hello World应用程序的build.xml。

This is my first attempt at writing an ANT script. This is my build.xml for a simple Hello World app using Spring.

<project name="MyFirstApp" default="jar" basedir="..">  
    <property name="src" location="src"/>
    <property name="build" location="build"/>
    <property name="lib" location="/WebContent/WEB-INF/lib"/>   
    <path id="classpath-example">   
        <fileset dir="${build}" includes="*.jar"/>
    </path>
    <target name="clean">
        <delete dir="build"/>
    </target>
    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac srcdir="${src}" destdir="build/classes" includeantruntime="false"/>
        <classpath refid="classpath-example"/>
    </target>
    <target name="jar">
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/MyFirstApp.jar" basedir="build/classes"/>          
    </target>
    <target name="run">
        <java jar="build/jar/MyFirstApp.jar" fork="true"/>
    </target>
</project>

当我尝试运行此下面的错误信息被显示出来。

when i try to run this the following error message is displayed.

问题:无法创建任务或类型的类路径
原因:这个名字是不确定的。
操作:检查拼写。
操作:检查所有的自定义任务/类型已经被宣布。
措施:检查所有/声明已经发生

Problem: failed to create task or type classpath Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any / declarations have taken place.

有人能告诉我什么是必须要做的?

Can someone please tell me what is to be done?

在我第一次运行Ant脚本,生成JAR文件。当我试图再次运行它,它提供了以下提到的错误。

The first time i ran the ANT script, the JAR file was generated. When i tried running it again , it gives the below mentioned error.

清理:
   [删除]删除目录F:\\ SHIL \\ JAVA \\弹簧工作区\\ myfirstapp1 \\建立

clean: [delete] Deleting directory F:\shil\JAVA\Spring Workspace\myfirstapp1\build

compile:
     [echo] compiling
    [mkdir] Created dir: F:\shil\JAVA\Spring Workspace\myfirstapp1\build\classes

    [javac] Compiling 5 source files to F:\shil\JAVA\Spring Workspace\myfirstapp
1\build\classes
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:4: package javax.servlet does not exist
    [javac] import javax.servlet.ServletException;
    [javac]                     ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:5: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServlet;
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:6: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServletRequest;
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:7: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServletResponse;
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:12: cannot find symbol
    [javac] symbol: class HttpServlet
    [javac] public class HelloWorldServlet extends HttpServlet {
    [javac]                                        ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:26: cannot find symbol
    [javac] symbol  : class HttpServletRequest
    [javac] location: class my.hello.servlet.HelloWorldServlet
    [javac]     protected void doGet(HttpServletRequest request, HttpServletResp
onse response) throws ServletException, IOException {
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:26: cannot find symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: class my.hello.servlet.HelloWorldServlet
    [javac]     protected void doGet(HttpServletRequest request, HttpServletResp
onse response) throws ServletException, IOException {
    [javac]                                                      ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:26: cannot find symbol
    [javac] symbol  : class ServletException
    [javac] location: class my.hello.servlet.HelloWorldServlet
    [javac]     protected void doGet(HttpServletRequest request, HttpServletResp
onse response) throws ServletException, IOException {
    [javac]
                      ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:33: cannot find symbol
    [javac] symbol  : class HttpServletRequest
    [javac] location: class my.hello.servlet.HelloWorldServlet
    [javac]     protected void doPost(HttpServletRequest request, HttpServletRes
ponse response) throws ServletException, IOException {
    [javac]                           ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:33: cannot find symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: class my.hello.servlet.HelloWorldServlet
    [javac]     protected void doPost(HttpServletRequest request, HttpServletRes
ponse response) throws ServletException, IOException {
    [javac]                                                       ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Hello
WorldServlet.java:33: cannot find symbol
    [javac] symbol  : class ServletException
    [javac] location: class my.hello.servlet.HelloWorldServlet
    [javac]     protected void doPost(HttpServletRequest request, HttpServletRes
ponse response) throws ServletException, IOException {
    [javac]
                       ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:4: package javax.servlet does not exist
    [javac] import javax.servlet.RequestDispatcher;
    [javac]                     ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:5: package javax.servlet does not exist
    [javac] import javax.servlet.ServletException;
    [javac]                     ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:6: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServlet;
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:7: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServletRequest;
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:8: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServletResponse;
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:15: cannot find symbol
    [javac] symbol: class HttpServlet
    [javac] public class WelcomeServlet extends HttpServlet {
    [javac]                                     ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:29: cannot find symbol
    [javac] symbol  : class HttpServletRequest
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]     protected void doGet(HttpServletRequest request, HttpServletResp
onse response) throws ServletException, IOException {
    [javac]                          ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:29: cannot find symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]     protected void doGet(HttpServletRequest request, HttpServletResp
onse response) throws ServletException, IOException {
    [javac]                                                      ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:29: cannot find symbol
    [javac] symbol  : class ServletException
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]     protected void doGet(HttpServletRequest request, HttpServletResp
onse response) throws ServletException, IOException {
    [javac]
                      ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:36: cannot find symbol
    [javac] symbol  : class HttpServletRequest
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]     protected void doPost(HttpServletRequest request, HttpServletRes
ponse response) throws ServletException, IOException {
    [javac]                           ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:36: cannot find symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]     protected void doPost(HttpServletRequest request, HttpServletRes
ponse response) throws ServletException, IOException {
    [javac]                                                       ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:36: cannot find symbol
    [javac] symbol  : class ServletException
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]     protected void doPost(HttpServletRequest request, HttpServletRes
ponse response) throws ServletException, IOException {
    [javac]
                       ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:41: cannot find symbol
    [javac] symbol  : class RequestDispatcher
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]             RequestDispatcher welcomeDispatcher = getServletContext(
).getRequestDispatcher("/Welcome.jsp");
    [javac]             ^
    [javac] F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\servlet\Welco
meServlet.java:41: cannot find symbol
    [javac] symbol  : method getServletContext()
    [javac] location: class my.hello.servlet.WelcomeServlet
    [javac]             RequestDispatcher welcomeDispatcher = getServletContext(
).getRequestDispatcher("/Welcome.jsp");
    [javac]                                                   ^
    [javac] Note: F:\shil\JAVA\Spring Workspace\myfirstapp1\src\my\hello\HelloWo
rldApp.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] 25 errors

BUILD FAILED
F:\shil\JAVA\Spring Workspace\myfirstapp1\ant\build.xml:19: Compile failed; see
the compiler error output for details.

Total time: 1 second

为什么这不会发生的第一次?有人可以请帮助?

why did this not happen the first time? can someone please help?

推荐答案

&LT;类路径&GT; 里面的编译目标应该嵌套在&LT; javac的方式&gt; 元素

The <classpath> inside your compile target should be nested inside the <javac> element.

另外值得一提的是,有很多蚂蚁(事实上,大多数构建系统)的动力来自于目标之间的依赖关系声明。在您的例子,它没有任何意义,运行 JAR 目标,而没有首先执行编译目标,否则,没有类文件的jar - 或者更糟,你会手工运行 JAR ,但忘记运行编译第一,与出过期类的JAR文件结束。因此, JAR 目标应取决于编译目标。这样一来,只要您运行的 JAR 目标,任何更改的类会自动先编译。同样,运行目标应取决于 JAR 目标。

It's also worth noting that a lot of the power of ant (and, indeed, most build systems) comes from declaring dependencies between targets. In your example, it doesn't make any sense to run the jar target without first having run the compile target, otherwise, there are no class files to jar - or worse, you'll run jar by hand, but forget to run compile first and end up with out-of-date classes in your JAR file. So, the jar target should depend on the compile target. That way, whenever you run the jar target, any changed class will automatically be compiled first. Similarly, the run target should depend on the jar target.

这篇关于错误,包括ant脚本外部JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆