我正在开发我的第一个Java应用程序。一位同事开始了它,但没有时间完成它。她是一位经验丰富的Java程序员,但我不是。但是,该应用程序足够小,它似乎是我可以作为我的第一个Java应用程序的项目(我使用JVM语言,如Clojure,所以我有一些背景暴露于JVM的世界)。
我正在添加将数据输出为JSON的功能。我想使用谷歌的Gson课程:
http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.google.code.gson%22
com.google.code.gson
我的同事没有外部依赖,因此她只是从命令行编译代码。现在我正在添加第三方依赖项,我想我应该切换到构建工具。我选择Buildr:http://buildr.apache.org/extending.html
我决定下载构成com.google.code.gson的3个Jar文件:
GSON-2.2.4-javadoc.jar
GSON-2.2.4-sources.jar
GSON-2.2.4.jar
我不确定如何将它们包含在我的Buildr项目中。
我使用“buildr”命令来建立Buildr喜欢的默认目录。但第三方罐子没有明显的文件夹。
我尝试了构建文件的许多变体。我最新的迭代是:
# Version number for this release
VERSION_NUMBER = "1.0.0"
# Group identifier for your projects
GROUP = "buildr_fdg"
COPYRIGHT = "2014, Open"
GOOGLEGSON = ['gson-2.2.4-javadoc.jar', 'gson-2.2.4-sources.jar', 'gson-2.2.4.jar']
# Specify Maven 2.0 remote repositories here, like this:
repositories.remote << "http://repo1.maven.org/maven2"
desc "The Buildr_fdg project -- creating JSON object full of fake data since we don't have enough real data ."
define "buildr_fdg" do
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
compile.with GOOGLEGSON
resources
test.compile.with # Add classpath dependencies
package(:jar)
end
但是我得到了这些错误:
buildr build
(in /Users/cerhov/projects/openz/lofdg/buildr_fdg, development)
Building buildr_fdg
Compiling buildr_fdg into /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/classes
/Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java:8: package com.google.code does not exist
import com.google.code.*;
^
/Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java:27: cannot find symbol
symbol : class Gson
location: class com.company.Main
Gson gson = new GsonBuilder().setPrettyPrinting().create();
^
/Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java:27: cannot find symbol
symbol : class GsonBuilder
location: class com.company.Main
Gson gson = new GsonBuilder().setPrettyPrinting().create();
^
Note: /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors
Buildr aborted!
RuntimeError : Failed to compile, see errors above
(See full trace by running task with --trace)
cerhov : 15:33:25 : ~/projects/openz/lofdg/buildr_fdg $ buildr build
(in /Users/cerhov/projects/openz/lofdg/buildr_fdg, development)
Building buildr_fdg
Buildr aborted!
RuntimeError : Don't know how to build task '/Users/cerhov/projects/openz/lofdg/buildr_fdg/com.google.code.gson'
如何告诉Buildr我的第三方罐子?
答案 0 :(得分:2)
向Buildr项目添加依赖项的最简单方法是使用&#34; maven&#34;图书馆的坐标。所以我相信你要做的就是用像
这样的东西替换GOOGLEGSONGOOGLEGSON = ['com.google.code.gson:gson:jar:2.2.4']
这与对Maven central的引用相结合应该意味着Buildr会下载依赖项并将其添加到类路径中。