构建与json相关的问题

时间:2015-08-05 20:31:34

标签: java json xml ant

我在尝试运行antbuild时在控制台中收到这些错误。请帮我解决这些错误。我还在Web \ lib中包含了所有必需的罐子。

Buildfile: J:\workspace\new\bluemixx\WordGuess\build.xml
clean:
   [delete] Deleting directory J:\workspace\new\bluemixx\WordGuess\bin
init:
    [mkdir] Created dir: J:\workspace\new\bluemixx\WordGuess\bin
build-project:
     [echo] WebStarterApp: J:\workspace\new\bluemixx\WordGuess\build.xml
    [javac] Compiling 7 source files to J:\workspace\new\bluemixx\WordGuess\bin
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:7: error: package org.apache.wink.json4j does not exist
    [javac] import org.apache.wink.json4j.JSONArray;
    [javac]                              ^
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:8: error: package org.apache.wink.json4j does not exist
    [javac] import org.apache.wink.json4j.JSONObject;
    [javac]                              ^
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Category.java:18: error: package com.fasterxml.jackson.annotation does not exist
    [javac] import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
    [javac]                                        ^
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Category.java:19: error: package com.fasterxml.jackson.annotation does not exist
    [javac] import com.fasterxml.jackson.annotation.JsonProperty;
    [javac]                                        ^
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Category.java:21: error: cannot find symbol
    [javac] @JsonIgnoreProperties({"id", "revision"})
    [javac]  ^
    [javac]   symbol: class JsonIgnoreProperties
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Word.java:18: error: package com.fasterxml.jackson.annotation does not exist
    [javac] import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
    [javac]                                        ^
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Word.java:19: error: package com.fasterxml.jackson.annotation does not exist
    [javac] import com.fasterxml.jackson.annotation.JsonProperty;
    [javac]                                        ^
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Word.java:21: error: cannot find symbol
    [javac] @JsonIgnoreProperties({"id", "revision"})
    [javac]  ^
    [javac]   symbol: class JsonIgnoreProperties
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Category.java:24: error: cannot find symbol
    [javac]     @JsonProperty("_id")
    [javac]      ^
    [javac]   symbol:   class JsonProperty
    [javac]   location: class Category
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Category.java:27: error: cannot find symbol
    [javac]     @JsonProperty("_rev")
    [javac]      ^
    [javac]   symbol:   class JsonProperty
    [javac]   location: class Category
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Word.java:24: error: cannot find symbol
    [javac]     @JsonProperty("_id")
    [javac]      ^
    [javac]   symbol:   class JsonProperty
    [javac]   location: class Word
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\model\Word.java:27: error: cannot find symbol
    [javac]     @JsonProperty("_rev")
    [javac]      ^
    [javac]   symbol:   class JsonProperty
    [javac]   location: class Word
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:27: error: cannot find symbol
    [javac]             JSONObject obj = new JSONObject(System.getenv("VCAP_SERVICES"));
    [javac]             ^
    [javac]   symbol:   class JSONObject
    [javac]   location: class CloudantConnection
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:27: error: cannot find symbol
    [javac]             JSONObject obj = new JSONObject(System.getenv("VCAP_SERVICES"));
    [javac]                                  ^
    [javac]   symbol:   class JSONObject
    [javac]   location: class CloudantConnection
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:28: error: cannot find symbol
    [javac]             String[] names = JSONObject.getNames(obj);
    [javac]                              ^
    [javac]   symbol:   variable JSONObject
    [javac]   location: class CloudantConnection
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:33: error: cannot find symbol
    [javac]                         JSONArray val = obj.getJSONArray(name);
    [javac]                         ^
    [javac]   symbol:   class JSONArray
    [javac]   location: class CloudantConnection
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:34: error: cannot find symbol
    [javac]                         JSONObject serviceAttr = val.getJSONObject(0);
    [javac]                         ^
    [javac]   symbol:   class JSONObject
    [javac]   location: class CloudantConnection
    [javac] J:\workspace\new\bluemixx\WordGuess\src\com\bluemix\hangman\data\CloudantConnection.java:35: error: cannot find symbol
    [javac]                         JSONObject credentials = serviceAttr.getJSONObject("credentials");
    [javac]                         ^
    [javac]   symbol:   class JSONObject
    [javac]   location: class CloudantConnection
    [javac] 18 errors

BUILD FAILED
J:\workspace\new\bluemixx\WordGuess\build.xml:30: Compile failed; see the compiler error output for details.

Total time: 539 milliseconds

我在尝试运行antbuild时在控制台中收到这些错误。请帮我解决这些错误。我还在Web \ lib中包含了所有必需的罐子。

1 个答案:

答案 0 :(得分:2)

请确保通过ant正确编译类,并在准备jar / war时...确保将basedir指定为包含所有类的目录,ant编译源java的目录代码到类。

一个简单的例子如下所示

`

<target name="clean">
    <delete dir="build"/>
</target>

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

<target name="jar">
    <mkdir dir="build/jar"/>
    <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
        <manifest>
            <attribute name="Main-Class" value="oata.HelloWorld"/>
        </manifest>
    </jar>
</target>

<target name="run">
    <java jar="build/jar/HelloWorld.jar" fork="true"/>
</target>

` 在这里你可以看到编译目标将java代码编译成build / classes,jar目标从build / classes目录中的类创建jar