简体   繁体   English

Stanford-CoreNLP和Stanford-Parser中的Maven类名冲突

[英]Maven class name collision in Stanford-CoreNLP and Stanford-Parser

My (maven)project is dependent on both stanford-CoreNLP and stanford-Parser and apparently the (lexicalized)parser of each dependency is producing different outputs, they are not alike. 我的(maven)项目同时依赖stanford-CoreNLP和stanford-Parser,显然每个依赖项的(词法化)解析器产生不同的输出,但它们并不相同。

My question is that how can I determine which package the parser should be loaded from ? 我的问题是,如何确定解析器应从哪个包加载? the parser class has a same name in both packages: edu.stanford.nlp.parser.lexparser.LexicalizedParser and maven automatically loads the class from stanford-coreNLP package while I want it to be loaded from stanford-Parser. 解析器类在两个包中具有相同的名称: edu.stanford.nlp.parser.lexparser.LexicalizedParser和maven自动从stanford-coreNLP包中加载该类,而我希望从stanford-parser中加载它。

I'd appreciate if you please help me with your suggestions. 如果您能帮助我提出建议,我们将不胜感激。

I would raise a bug asking them to move the lexical parser into a new maven artifact (or several of them), so you can distinguish them. 我会提出一个错误,要求他们将词法分析器移动到新的Maven工件(或其中的几个)中,以便您可以区分它们。

If that doesn't happen, you have two options: 如果没有发生,则有两种选择:

  1. Use the Maven shade plugin (as suggested by ooxi) 使用Maven阴影插件(如ooxi所建议)
  2. Delete the offending classes 删除有问题的课程

Breakdown of the second approach: 第二种方法的细分:

  1. Use you favorite ZIP tool to open the JAR archive. 使用您喜欢的ZIP工具打开JAR存档。
  2. Delete the offending packages. 删除有问题的软件包。
  3. Copy the original POM 复制原始POM
  4. Change the version version to something like 1.1.MythBuster.1 or 1.1.no-lexer.1 将版本版本更改为类似1.1.MythBuster.11.1.no-lexer.1
  5. Use mvn file:install to install the modified artifact in your local repo 使用mvn file:install将修改后的工件安装在本地仓库中
  6. Test it 测试一下
  7. Use mvn deploy:deploy-file to install the modified artifact in your company's repo 使用mvn deploy:deploy-file在公司的仓库中安装修改后的工件

I prefer the second approach since it makes sure the build has a clean classpath, people know that you messed with the original file and it's pretty obvious what is going on. 我更喜欢第二种方法,因为它可以确保构建具有干净的类路径,人们知道您将原始文件弄乱了,并且很明显正在发生什么。

I once had this problem and could solve it by using a virtual package depending on the two conflicting dependencies (in your case stanford-CoreNPL and stanford-Parser) and merging them using the Maven shade plugin . 我曾经遇到过这个问题,可以通过使用依赖于两个相互冲突的依赖项(在您的情况下为stanford-CoreNPL和stanford-Parser)的虚拟包并使用Maven shade plugin合并它们来解决问题。

When shading only one class will be in the virtual package, depending on the order of <dependency /> tags. 着色时,根据<dependency />标记的顺序,虚拟包中将只有一个类。

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

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