简体   繁体   English

为什么我无法在Maven存储库中的Android项目中使用库? 如何为此编写正确的pom.xml?

[英]Why I can't use a library in my Android project from Maven repository? How to write a correct pom.xml for this?

I want to use Jackson JSON parser library in my android project. 我想在我的Android项目中使用Jackson JSON解析器库。 I saw this library in Maven repository, but I don't know how to use it. 我在Maven存储库中看到了这个库,但是我不知道如何使用它。 I've downloaded sources from the Maven repository and Jackson jars and attached sources to jar, but in the logcat I saw error message NoClassDefFoundError. 我已经从Maven资源库和Jackson罐下载了源,并将源附加到jar,但是在logcat中,我看到了错误消息NoClassDefFoundError。 When googling I' ve read that I have to declare Jackson dependencies in pom.xml file.I' ma newbie in Java development so I don't know what all these means. 谷歌搜索时,我读到我必须在pom.xml文件中声明Jackson依赖关系。我是Java开发中的新手,所以我不知道所有这些意味着什么。 And have some questions: 还有一些问题:

1.How to write pom.xml for the Jackson library 1.如何为Jackson库编写pom.xml

2.Where to put this pom.xml 2.将pom.xml放在哪里

3. Do I really need to install Maven if I just want to use the library. 3.如果我只想使用该库,是否真的需要安装Maven。

4. What else I need to begin work with the library? 4.我还需要什么来开始使用图书馆?

No, you do not need to write a pom file, unless you are using Maven for building (in which case you need it regardless of Jackson). 不,您不需要编写pom文件,除非您使用Maven进行构建(在这种情况下,无论Jackson如何,都需要它)。

What you need are just Jackson jars -- there is more than one, since some projects only need some pieces. 您需要的只是Jackson罐子-不止一个,因为有些项目只需要几块。 This page: 这一页:

http://wiki.fasterxml.com/JacksonDownload http://wiki.fasterxml.com/JacksonDownload

should show what you need, and where to get them from. 应该显示您的需求以及从何处获取它们。 If you are starting from scratch, I would strongly recommend using Jackson 2.1 (not 1.9). 如果您是从头开始,我强烈建议您使用Jackson 2.1(而不是1.9)。 And then you most likely need 3 jars (jackson-annotations, jackson-databind, jackson-core) -- although minimal is just jackson-core , if you use so-called "streaming API" (low-level, highest performance, but more work). 然后,您很可能需要3个jar(jackson-annotation,jackson-databind,jackson-core)-尽管最小的只是jackson-core ,如果您使用所谓的“流API”(低级别,最高性能,但更多的工作)。

The benefit of using Maven would be just that you can define logical depenendency (group and artifact id of jar), and Maven would resolve it to physical jar, as well as references to other jars. 使用Maven的好处是,您可以定义逻辑依赖关系(jar的组和工件ID),并且Maven会将其解析为物理jar,以及对其他jar的引用。

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

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