当前位置: 动力学知识库 > 问答 > 编程问答 >

java - 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.

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.

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.

If that doesn't happen, you have two options:

  1. Use the Maven shade plugin (as suggested by ooxi)
  2. Delete the offending classes

Breakdown of the second approach:

  1. Use you favorite ZIP tool to open the JAR archive.
  2. Delete the offending packages.
  3. Copy the original POM
  4. Change the version version to something like 1.1.MythBuster.1 or 1.1.no-lexer.1
  5. Use mvn file:install to install the modified artifact in your local repo
  6. Test it
  7. Use mvn deploy:deploy-file to install the modified artifact in your company's repo

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.

When shading only one class will be in the virtual package, depending on the order of <dependency /> tags.

分享给朋友:
您可能感兴趣的文章:
随机阅读: