简体   繁体   English

xpages:如何使用第三方Java库

[英]xpages: how to use 3rd party java libraries

I would like to use a 3rd party java library in my xpage application. 我想在我的xpage应用程序中使用第3方Java库。 I found some instructions on the Web, how jars can be used. 我在网上找到了一些有关如何使用jar的说明。 Can anyone tell me what am I doing with Java code, which comes in a simple folder? 谁能告诉我我在用一个简单的文件夹中的Java代码做什么?

I would like to use JsonPath . 我想使用JsonPath

I'd like to preface my answer with "I'm sorry". 我想以“对不起”开头回答。 This sort of thing gets more complicated than it should. 这种事情变得比它应该的复杂。

In the simple case of your question - how do I add a source-form Java project to my NSF - it's not too bad. 在您的问题的简单情况下-如何将源代码形式的Java项目添加到我的NSF中-这还不错。 I'd take the tack of creating a new source folder in Project Explorer, say "src-jsonpath" and importing the source from the filesystem. 我打算在Project Explorer中创建一个新的源文件夹,说“ src-jsonpath”,然后从文件系统导入源。 However, in this case, that won't work too well. 但是,在这种情况下,这将无法很好地工作。

The trouble is that JsonPath has a good number of dependencies, which you would ALSO need to track down. 问题在于JsonPath具有大量依赖关系,您还需要跟踪这些依赖关系。 It's available in Maven, but, since Designer doesn't know anything about Maven, there are some hoops. 它在Maven中可用,但是,由于Designer对Maven一无所知,因此有些麻烦。

The simplest variant of this technique I found was via https://stackoverflow.com/a/15484858/858171 , which suggests a two-step process for downloading the library and its various dependencies without having to create an actual Maven project. 我发现的这项技术的最简单变体是通过https://stackoverflow.com/a/15484858/858171提出的,该过程建议分两步进行 ,以下载库及其各种依赖项,而不必创建实际的Maven项目。 It (and I will now) assumes you have Maven set up on your system - if you don't, you can find sort-of-okay instructions on maven.apache.org . 它(现在我要假设)假设您已经在系统上设置了Maven-如果没有,则可以在maven.apache.org上找到不错的说明。

With the other major assumption that you're on or can use a Mac or other Unix-alike system, these two lines should download the libraries to the current directory: 在您使用或可以使用Mac或其他类似Unix的系统的另一个主要假设下,这两行代码应将库下载到当前目录:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=com.jayway.jsonpath:json-path:2.0.0:jar -DoutputDirectory=.
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=com.jayway.jsonpath:json-path:2.0.0:pom -DoutputDirectory=.
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy-dependencies -f json-path-2.0.0.pom -DoutputDirectory=.

The first line actually retrieves the jar for the JsonPath library. 第一行实际上是为JsonPath库检索jar。 The second then retrieves its pom file (project descriptor) - this file isn't useful for your needs directory, but is needed for the next step. 然后第二个检索其pom文件(项目描述符)-该文件对您的需求目录没有用,但在下一步中是必需的。 The third line then uses this pom file to download the project's dependencies (and its dependencies' dependencies) to the current directory. 然后,第三行使用此pom文件将项目的依赖项(及其依赖项的依赖项)下载到当前目录。

Once you've done this, you'll end up with a pile of jar files that you can then either put into the NSF or (probably better, with this many) onto the filesystem. 完成此操作后,您将得到一堆jar文件,然后可以将它们放入NSF或(可能会有很多)放入文件系统中。 The best route would be to turn them into an XSP OSGi library, but that's a larger topic that I should blog about eventually. 最好的方法是将它们转换为XSP OSGi库,但这是我最终应该写博客的一个较大主题。

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

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