Stanford CoreNLP: Building Error (NoSuchMethodError) - netbeans

Sorry if this is a newbie's question.
I was trying to use maven in Netbeans to build CoreNLP parser.
I first added dependency of stanford-corenlp 1.2.0. However, I always got an error while compiling my code. I tried to simplify my code to just create the StanfordCoreNLP object, but it still did not function with the same error message. I guess here might come with the main trouble spot then.
My simplified code shows as:
import java.util.Properties;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
The error message:
Exception in thread "main" java.lang.NoSuchMethodError:
edu.stanford.nlp.process.PTBTokenizer.factory
(Ledu/stanford/nlp/process/LexedTokenFactory;Ljava/lang/String;)Ledu/stanford/nlp/objectbank/TokenizerFactory;
at edu.stanford.nlp.pipeline.PTBTokenizerAnnotator.<init>(PTBTokenizerAnnotator.java:42)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$1.create(StanfordCoreNLP.java:365)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$1.create(StanfordCoreNLP.java:355)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:62)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:328)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:194)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:184)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:176)
at com.mycompany.hellocore.App.main(App.java:26)
I also tried the same thing via maven on Eclipse, the error message is still the same. Can anyone give me some suggestions? Thanks!
OS: Mac Lion /
Java version: 1.6.0_29
[Update]
01-6-2012 Based on Sri Sankaran's suggestion, i tried mvn dependency: tree:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hellocore 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) # hellocore ---
[INFO] com.mycompany:hellocore:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] \- edu.stanford.nlp:stanford-corenlp:jar:1.2.0:compile
[INFO] +- xom:xom:jar:1.2.5:compile
[INFO] | +- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] | +- xerces:xercesImpl:jar:2.8.0:compile
[INFO] | \- xalan:xalan:jar:2.7.0:compile
[INFO] \- joda-time:joda-time:jar:2.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.483s
[INFO] Finished at: Fri Jan 06 08:55:06 EST 2012
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------
The setting in my Netbeans:
But it seems like the library in need looks the same as what is already downloaded in Netbeans. The project still stops while Adding annotator tokenize.
[Update]
01-09-2012
After i reinstalled my system, the problem was gone. So i think the code and the module are both correct. The classpath directories might be just messed up by me. Thank you for all people's helps.
Just a gentle reminder for people using corenlp via Netbeans. In addition to the standard dependency of stanford-corenlp.jar. If you want to inlcude the stanford-corenlp-models.jar into your project. Seems like you also need to specify the <classifier> to add the models to the dependency repository.
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>1.2.0</version>
<classifier>models</classifier>
</dependency>

You need to include model (POS tag, NER, Coref, etc), so your annotator worked.
You can get it here

The usage of Standford NLP suggests that there are other dependencies. If they aren't transitively included in the classpath by virtue of the stated dependency on stanford-corenlp 1.2.0 you will have to explicitly state these other dependencies as well. The command mvn dependency:tree should display your effective dependency tree.

Related

Conflicts in spark-core dependencies. How does it work?

The entrypoint to my issues was an exception:
[info] Cause: com.fasterxml.jackson.databind.JsonMappingException: Incompatible Jackson version: 2.8.4
[info] at com.fasterxml.jackson.module.scala.JacksonModule.setupModule(JacksonModule.scala:64)
[info] at com.fasterxml.jackson.module.scala.JacksonModule.setupModule$(JacksonModule.scala:51)
[info] at com.fasterxml.jackson.module.scala.DefaultScalaModule.setupModule(DefaultScalaModule.scala:19)
[info] at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:745)
[info] at org.apache.spark.rdd.RDDOperationScope$.<init>(RDDOperationScope.scala:82)
[info] at org.apache.spark.rdd.RDDOperationScope$.<clinit>(RDDOperationScope.scala)
[info] at org.apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:152)
[info] at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:127)
[info] at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:83)
[info] at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:81)
It occurred after upgrade of Spark. I managed to overcome this problem, however I still don't understand root cause.
It looks like problem with Spark dependencies, please look:
https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.12/2.4.7
It needs com.fasterxml.jackson.core » jackson-databind 2.6.7.3.
No problem.
Further, it needs as well:
https://mvnrepository.com/artifact/org.json4s/json4s-jackson_2.12/3.5.3
No problem.
However, https://mvnrepository.com/artifact/org.json4s/json4s-jackson_2.12/3.5.3 requires https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.8.4
Now, we can see that spark-2.4.7 introduced dependencies conflict between jackson-databind itself. Where am I wrong in my reasoning?
As you can see in the parent-pom, com.fasterxml.jackson.core.* is excluded from json4s-jackson:
https://github.com/apache/spark/blob/v2.4.7/pom.xml#L755
So, there is no conflict after all

Can't integrate AssertJ into TestNG (Java 1.8, Maven)

Added dependency into pom.xml
After adding static import (tried also many with all list) and assertion (AssertThat) - it doesn't work.
import static org.assertj.core.api.Assertions.*;
It's not finding any JAR for AssertJ. After pressing 2 times control+space - there are no suggestions.
I have seen AssertJ working with Idea, please double check your classpath in Idea.
You can check hos maven resolve your dependencies with mvn dependency:tree, you should see something like:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # assertj-examples-java-8 ---
[INFO] org.assertj:assertj-examples-java-8:jar:1.0
[INFO] +- org.assertj:assertj-core:jar:3.12.2-SNAPSHOT:test

How to force SBT to use Javadoc instead of Scaladoc?

I have Java based a Play & Akka project that is built with SBT, is there any way to tell SBT to run Javadoc instead of Scaladoc when building the project? The SBT documentation says that
“sbt will run javadoc if there are only Java sources in the project. If there are any Scala sources, sbt will run scaladoc.”
and there are no Scala files in the project but Scaladoc is still run. I assume that this is because the Play plugin is converting the view templates and conf/routes file into Scala code before compilation happens.
tl;dr Change sources in (Compile, doc) to exclude *.scala files so scaladoc doesn't kick in.
As you can read below sources in (Compile, doc) holds all sources, both managed and unmanaged in a project:
> inspect compile:doc::sources
[info] Task: scala.collection.Seq[java.io.File]
[info] Description:
[info] All sources, both managed and unmanaged.
With some filtering you can achieve your goal quite easily - use the following in build.sbt:
sources in (Compile, doc) <<= sources in (Compile, doc) map { _.filterNot(_.getName endsWith ".scala") }
A sample project's session (comments with // are mine to enhance reading):
// display current setting's value
> show compile:doc::sources
[info] ArrayBuffer(/Users/jacek/sandbox/sbt-learning-space/src/main/scala/x.scala, /Users/jacek/sandbox/sbt-learning-space/src/main/java/Hello.java)
[success] Total time: 0 s, completed Aug 24, 2014 9:31:34 PM
// generate docs - scaladoc kicks in since there are scala files
> doc
[info] Updating {file:/Users/jacek/sandbox/sbt-learning-space/}sbt-learning-space...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Main Scala API documentation to /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api...
model contains 3 documentable templates
[info] Main Scala API documentation successful.
Hello
[success] Total time: 1 s, completed Aug 24, 2014 9:32:15 PM
// change the value of sources in the current session only - use session save to retain it
> set sources in (Compile, doc) <<= sources in (Compile, doc) map { _.filterNot(_.getName endsWith ".scala") }
[info] Defining compile:doc::sources
[info] The new value will be used by compile:doc
[info] Reapplying settings...
[info] Set current project to hello (in build file:/Users/jacek/sandbox/sbt-learning-space/)
// display current setting's value - it only holds the single java file
> show compile:doc::sources
[info] ArrayBuffer(/Users/jacek/sandbox/sbt-learning-space/src/main/java/Hello.java)
[success] Total time: 0 s, completed Aug 24, 2014 9:33:23 PM
// generate docs - javadoc is properly generated
> doc
[info] Main Java API documentation to /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api...
[info] Loading source file /Users/jacek/sandbox/sbt-learning-space/src/main/java/Hello.java...
[info] Constructing Javadoc information...
[info] Standard Doclet version 1.7.0_65
[info] Building tree for all the packages and classes...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/Hello.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/package-frame.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/package-summary.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/package-tree.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/constant-values.html...
[info] Building index for all the packages and classes...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/overview-tree.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/index-all.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/deprecated-list.html...
[info] Building index for all classes...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/allclasses-frame.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/allclasses-noframe.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/index.html...
[info] Generating /Users/jacek/sandbox/sbt-learning-space/target/scala-2.10/api/help-doc.html...
[info] Main Java API documentation successful.
Hello
[success] Total time: 1 s, completed Aug 24, 2014 9:34:01 PM
You could try and integrate genjavadoc into sbt, in order to generate a javadoc.
The ScalaDoc can still be generated using the normal doc task,
whereas the JavaDoc can be generated using genjavadoc:doc.
Another approach, allowed with scala 2.12.0-RC1 (Sept. 2016) and SI 4826 is to let scaladoc run! It will process javadoc comments!
Scaladoc already processes Java sources and produces Scaladoc for them.
It just ignores the doc comments.
Many of our Scala codebases have at least some Java in them for various reasons.
It'd be nice if Scaladoc could generate full documentation for these mixed codebases, including all doc comments.

Eclipse maven jboss project - what do I need to add to the pom.xml so maven can compile?

I managed to set up my Jboss WTP project in maven. Right click on the project > Run as > Run on server (Jboss 7) works fine. But if I go ahead and delete the target directory and then try to execute compile goal it fails with missing dependencies:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.\
singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building PROJECT 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # PROJECT ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\path\\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # PROJECT ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to C:\path\\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/path/to/file/Controller.java:[14,21] package javax.servlet does not exist
#..... NOTICE THIS COMES FROM A CUSTOM JAR
[ERROR] /C:/path/to/file/DataServlet.java:[3,30] package gr.uoa.di.java.helpers does not exist
#.....
[ERROR] /C:/path/to/file/DataServlet.java:[26,32] package javax.servlet.annotation does not exist
[ERROR] /C:/path/to/file/DataServlet.java:[28,26] package javax.servlet.http does not exist
#.....
[INFO] 49 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
If I clean the project so the target directory is populated with classes then try to compile the project all fine:
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # DataCollectionServlet ---
[INFO] Nothing to compile - all classes are up to date
I have 1 question:
What exactly should I add to the pom.xml to reproduce the compilation environment of the Run on Server eclipse command ? EDIT: For instance adding:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
to the pom solved the "servlet API not found" issue - but is it the way to go ? Or should I add something like:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-spec-api</artifactId>
<version>7.1.1.Final</version>
</dependency>
(see here). NB: adding the dependencies suggested by m2e plugin would result in a huge pom - moreover I am not sure all of it would be needed (it's a plain servlet/jsp project):
I am on Eclipse Luna Java EE pack, maven 3.1 (the one that comes with eclipse) and using Jboss 7.1.1.Final
I ended up just adding:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.1</version>
<scope>provided</scope>
</dependency>
This transitively added the servlet-api:
Still don't know if adding this is the right way to add jstl 1.2.1 - notice it adds the jstl 1.2 api (EDIT: it isn't: Standard way of adding JSLT 1.2.1 in a Maven Project?)
I also still have problems with my homebrew jar (Can maven treat WEB-INF\lib the way eclipse (and m2e) does?) but closing this for now.

maven dependency not found in repository

I'm trying to run the project, which uses gwt-dev.
The instructions are at: http://neiliscoding.blogspot.ru/2012/05/how-to-setup-examples-for-use-in-gxt-3.html?showComment=1362999279386
when I create dependency in terminal like: mvn install:install-file -DgroupId=com.google.gwt -DartifactId=gwt-dev -Dversion=2.5.0 -Dpackaging=jar -Dfile='/home/mikhail/Загрузки/libraries/gwt-2.5.0/gwt-dev.jar'
and add dependency to the pom.xml:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>2.5.0</version>
</dependency>
maven says:
[WARNING] You should not declare gwt-dev as a project dependency. This may introduce complex dependency conflicts
Downloading: http://repo1.maven.org/maven2/com/google/gwt/gwt-dev/2.5.0/gwt-dev-2.5.0-linux-libs.zip
[INFO] Unable to find resource 'com.google.gwt:gwt-dev:zip:linux-libs:2.5.0' in repository central (http://repo1.maven.org/maven2)
else if I remove it maven says:
[INFO] using GWT jars from project dependencies : 2.5.0
Downloading: http://repo1.maven.org/maven2/com/google/gwt/gwt-dev/2.5.0/gwt-dev-2.5.0-linux-libs.zip
[INFO] Unable to find resource 'com.google.gwt:gwt-dev:zip:linux-libs:2.5.0' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
So I have Build error in both cases. How to deal with such situation? help me please.
I didn't managed with this problem yet but I've just found that I used 1.2 version of maven plugin. I'm not shure it is the main problem, but I'd like to deal with it anyway. so, sinse I've added this plugin according to your first link, maven drops build error:
`
[INFO] Scanning for projects...
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for updates from central
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for updates from central
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Batch mode
[INFO] Archetype repository missing. Using the one from [org.codehaus.mojo:gwt-maven-plugin:2.5.1-rc1] found in catalog remote
[WARNING] Property module is missing. Add -Dmodule=someValue
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Archetype org.codehaus.mojo:gwt-maven-plugin:2.5.1-rc1 is not configured
Property module is missing.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Tue Mar 12 15:18:50 MSK 2013
[INFO] Final Memory: 27M/428M
`
and by the way, I use intellij IDEA
GWT stopped maintaining separate platform dependent libs for windows,linux and mac long time ago. GWT 1.7 was the last of such platform dependent libs. So "linux-libs" does not make sense in your error. I am guessing you are using a really old gwt-maven-plugin .
Move to latest gwt-maven-plugin.
Use <scope>provided</scope> for gwt-dev dependency to avoid it being pushed into WEB-INF/lib ( harmless but redundant )
Use global/central repository instead of installing it user repo locally.
You can also start off using GWT samples for maven projects here.
Note - your query might be a duplicate/similart to NetBeans + GWT 2.2.0 + Maven compile problem
Edit for new GWT release
GWT 2.5.1 has been released and also make note gwt-maven-plugin is of 2.5.0 ( 1 step behind GWT :)