I am trying to enable printing debugging information for a maven project. I added log4j as dependency to pom.xml and added log4j.properties as well as log4j2.properties with rootloger=DEBUG, sdout to src/main/resources folder. Then in the desired class, I initiate a logger in the desired class 'org.pakage1.ClassA' and add logger.debug() lines but nothing was shown in my consul. When I checked logger.isDebugEnabled() it returns false
pom.xml
<dependencies>
.....
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
log4j.properties and similarly log4j2
log4j.debug=true
log4j.rootLogger=DEBUG, stdout
log4j.appender.Stdout.threshold=debug
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %d [%t] %c{1} - %m%n
and as extra step I tried adding
log4j.logger.extendedsldnf.ExtendedSLDNFEvaluator=DEBUG
but it also did not work.
package package1;
......
class ClassA{
private Logger logger = LoggerFactory.getLogger(getClass());
......
public static void main(String []args){
logger.debug("message");
}
}
Knowing that I am getting warning
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Also the project has other sub-modules that also have logging enabled similarly and debugging messages works well when stated in the log4j.properties file
Is there something missing? How to check if there is something conflicting?
added log4j.properties as well as log4j2.properties
The first one is for log4j 1, the second one is for log4j 2.
Declaring both is not a way to solve your problem.
Use only which one that matches to your actual log4j version.
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Actual
binding is of type
[ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Indeed, the problem is rather clear : you want to use the log4J implementation as SLF4J binding but you have at runtime in the classpath at least one another SLF4J binding. Here is mentioned ContextSelectorStaticBinder from Logback that is another binding.
You have to have in the classpath at runtime a single implementation/binding for SLF4J.
To solve your problem, it is rather simple.
As you use Maven, I propose you to execute the mvn dependency:tree command from the agreggator pom of your application or if you have not agreggator pom, from the pom that packages your application.
This command will write as output the dependencies (including transitive dependencies pulled by your pom).
It will output something like that :
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) # Test-Spring-Boot ---
[INFO] Test-Spring-Boot:Test-Spring-Boot:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:1.4.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.4.4.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:1.4.4.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.4.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.4.RELEASE:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.1.9:compile
[INFO] | | | +- ch.qos.logback:logback-core:jar:1.1.9:compile
[INFO] | | | \- org.slf4j:slf4j-api:jar:1.7.22:compile
[INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.22:compile
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.22:compile
[INFO] | | \- org.slf4j:log4j-over-slf4j:jar:1.7.22:compile
[INFO] | +- org.springframework:spring-core:jar:4.3.6.RELEASE:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.4.RELEASE:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.11:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.11:compile
[INFO] | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.11:compile
[INFO] +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | \- com.fasterxml:classmate:jar:1.3.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.6:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.6:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.8.6:compile
[INFO] +- org.springframework:spring-web:jar:4.3.6.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.3.6.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:4.3.6.RELEASE:compile
[INFO] | \- org.springframework:spring-context:jar:4.3.6.RELEASE:compile
[INFO] \- org.springframework:spring-webmvc:jar:4.3.6.RELEASE:compile
[INFO] \- org.springframework:spring-expression:jar:4.3.6.RELEASE:compile
You have just to identify from where the logback dependency is pulled.
Once having identified it, remove the dependency it if it is an dependency explicitly declared from our own pom.
If it is a transitive dependency, use the exclusion dependency mechanism of Maven.
If you want to use log4j appender to print slf4j logger's log, make sure that you have slf4j-log4j12 jar and remove logback jars, or it will be out of your control whether log4j or logback in use.
Related
We have an old drools library that've been upgrading to later versions of KIE, and Executable rule models caught my eye. When I started my migration, my dependencies looked like this:
<dependencies>
...
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${kie.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${kie.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>${kie.version}</version>
<extensions>true</extensions>
</plugin>
Using 7.26.0.Final. When I upgraded to 7.59.0.Final I added the compiler dependency as I was supposed to from the doc:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-model-compiler</artifactId>
<version>${kie.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${kie.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${kie.version}</version>
</dependency>
But my generate model now seems to fail:
[INFO] --- kie-maven-plugin:7.59.0.Final:generateModel (default-generateModel) # rules ---
[INFO] Using NEW implementation
[INFO] Using NEW implementation
[INFO] Artifact not fetched from maven: org.drools:drools-model-compiler:7.59.0.Final. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.kie:kie-ci:7.59.0.Final. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.apache.commons:commons-collections4:4.4. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.apache.commons:commons-lang3:3.12.0. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.kie:kie-api:7.59.0.Final. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.mvel:mvel2:2.4.12.Final. To enable the KieScanner you need kie-ci on the classpath
WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[ERROR] Unable to build KieBaseModel:plan-rules
InvalidExpressionErrorResult: Method equalsAnyIgnoreCase on class org.apache.commons.lang3.StringUtils with arguments [class java.lang.String, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method intersectionsStartsWith on class com.accolade.clinical.utils.RuleUtils with arguments [interface java.util.List, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method size on class java.lang.Object with arguments [] is missing
... (A lot more errors of this nature)
Why won't it pick up the dependencies even if I have maven CI and the plugin configured? Is there something I missed in the docs?
Edit:
As per the the first answer:
I tried replacing the 3 dependencies I've listed above with
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-engine</artifactId>
<version>${kie.version}</version>
</dependency>
But unfortunately kie doesn't want to use the new generate models method in this case:
[INFO] --- kie-maven-plugin:7.59.0.Final:generateModel (default-generateModel) # rules ---
[WARNING] You're trying to build rule assets in a project from an executable rule model, but you did not provide the required dependency on the project classpath.
To enable executable rule models for your project, add the `drools-model-compiler` dependency in the `pom.xml` file of your project.
[INFO]
[INFO] --- kie-maven-plugin:7.59.0.Final:generateDMNModel (default-generateDMNModel) # rules ---
[INFO]
[INFO] --- kie-maven-plugin:7.59.0.Final:generatePMMLModel (default-generatePMMLModel) # rules ---
[WARNING] Skipping `generatePMMLModel` because you did not provide the required dependency on the project classpath.
To enable it for your project, add the `drools-model-compiler` dependency in the `pom.xml` file of your project.
[INFO]
[INFO] --- kie-maven-plugin:7.59.0.Final:generateANC (default-generateANC) # rules ---
[INFO]
[INFO] --- kie-maven-plugin:7.59.0.Final:build (default-build) # rules ---
Here's an output of mvn dependency:tree:
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< com.mycompany:rules >---------------------
[INFO] Building Rules 5.0.0-SNAPSHOT
[INFO] --------------------------------[ kjar ]--------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # rules ---
[INFO] com.mycompany:rules:kjar:5.0.0-SNAPSHOT
[INFO] +- com.mycompany.acp.utilities:model-utilities:jar:7.1.0:compile
[INFO] | +- com.mycompany.acp.fhir:common-fhir:jar:8.2.0:compile
[INFO] | | +- io.swagger.core.v3:swagger-annotations:jar:2.1.10:compile
[INFO] | | +- io.swagger:swagger-annotations:jar:1.6.2:compile
[INFO] | | +- org.reflections:reflections:jar:0.9.12:compile
[INFO] | | | \- org.javassist:javassist:jar:3.26.0-GA:compile
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] | | | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.9.4:compile
[INFO] | | | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | | | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | | \- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] | +- com.github.java-json-tools:json-patch:jar:1.13:compile
[INFO] | +- com.github.java-json-tools:msg-simple:jar:1.2:compile
[INFO] | | \- com.github.java-json-tools:btf:jar:1.3:compile
[INFO] | +- com.github.java-json-tools:jackson-coreutils:jar:2.0:compile
[INFO] | +- com.contentful.java:java-sdk:jar:10.4.5:compile
[INFO] | | +- com.squareup.retrofit2:retrofit:jar:2.5.0:compile
[INFO] | | +- com.squareup.retrofit2:adapter-rxjava2:jar:2.5.0:compile
[INFO] | | +- com.squareup.retrofit2:converter-gson:jar:2.5.0:compile
[INFO] | | +- io.reactivex.rxjava2:rxjava:jar:2.2.6:compile
[INFO] | | | \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] | | +- com.squareup.okhttp3:okhttp:jar:3.12.12:compile
[INFO] | | | \- com.squareup.okio:okio:jar:1.15.0:compile
[INFO] | | +- com.google.code.gson:gson:jar:2.8.5:compile
[INFO] | | \- com.github.tony19:named-regexp:jar:0.2.5:compile
[INFO] | +- com.mycompany.acp.resources:singularity-models:jar:6.1.0:compile
[INFO] | | +- com.mycompany.acp-common-eventbus:models:jar:5.0.3:compile
[INFO] | | | \- com.amazonaws:aws-java-sdk-sns:jar:1.11.625:compile
[INFO] | | | \- com.amazonaws:aws-java-sdk-sqs:jar:1.11.625:compile
[INFO] | | +- com.amazonaws:aws-java-sdk-dynamodb:jar:1.12.18:compile
[INFO] | | | +- com.amazonaws:aws-java-sdk-s3:jar:1.12.18:compile
[INFO] | | | | \- com.amazonaws:aws-java-sdk-kms:jar:1.12.18:compile
[INFO] | | | +- com.amazonaws:aws-java-sdk-core:jar:1.12.18:compile
[INFO] | | | | +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] | | | | | \- org.apache.httpcomponents:httpcore:jar:4.4.13:compile
[INFO] | | | | +- software.amazon.ion:ion-java:jar:1.0.2:compile
[INFO] | | | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.12.3:compile
[INFO] | | | | \- joda-time:joda-time:jar:2.8.1:compile
[INFO] | | | \- com.amazonaws:jmespath-java:jar:1.12.18:compile
[INFO] | | +- com.amazonaws:aws-java-sdk-sts:jar:1.12.18:compile
[INFO] | | \- com.mycompany.acp.fhir:common-utilities:jar:8.2.0:compile
[INFO] | | \- org.springframework:spring-web:jar:5.3.8:compile
[INFO] | | +- org.springframework:spring-beans:jar:5.3.8:compile
[INFO] | | \- org.springframework:spring-core:jar:5.3.8:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.3.8:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.12.4:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.4:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.12.4:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] +- commons-io:commons-io:jar:2.11.0:compile
[INFO] +- org.mvel:mvel2:jar:2.4.12.Final:compile
[INFO] +- org.slf4j:slf4j-api:jar:2.0.0-alpha5:provided
[INFO] +- org.projectlombok:lombok:jar:1.18.20:provided
[INFO] +- org.drools:drools-engine:jar:7.59.0.Final:compile
[INFO] | +- org.kie:kie-api:jar:7.59.0.Final:compile
[INFO] | | \- org.kie.soup:kie-soup-maven-support:jar:7.59.0.Final:compile
[INFO] | +- org.kie:kie-internal:jar:7.59.0.Final:compile
[INFO] | +- org.drools:drools-core:jar:7.59.0.Final:compile
[INFO] | | +- org.kie.soup:kie-soup-xstream:jar:7.59.0.Final:compile
[INFO] | | +- org.drools:drools-core-reflective:jar:7.59.0.Final:compile
[INFO] | | +- org.drools:drools-core-dynamic:jar:7.59.0.Final:runtime
[INFO] | | \- commons-codec:commons-codec:jar:1.11:compile
[INFO] | +- org.drools:drools-compiler:jar:7.59.0.Final:compile
[INFO] | | +- org.kie:kie-memory-compiler:jar:7.59.0.Final:compile
[INFO] | | +- org.drools:drools-ecj:jar:7.59.0.Final:compile
[INFO] | | +- org.antlr:antlr-runtime:jar:3.5.2:compile
[INFO] | | \- com.thoughtworks.xstream:xstream:jar:1.4.17:compile
[INFO] | | \- io.github.x-stream:mxparser:jar:1.2.1:compile
[INFO] | | \- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | \- org.drools:drools-model-compiler:jar:7.59.0.Final:compile
[INFO] | +- org.drools:drools-canonical-model:jar:7.59.0.Final:compile
[INFO] | +- com.github.javaparser:javaparser-core:jar:3.13.10:compile
[INFO] | +- org.drools:drools-mvel-parser:jar:7.59.0.Final:compile
[INFO] | \- org.drools:drools-mvel-compiler:jar:7.59.0.Final:compile
[INFO] +- xerces:xercesImpl:jar:2.12.1:test
[INFO] | \- xml-apis:xml-apis:jar:1.4.01:test
[INFO] +- com.google.guava:guava:jar:30.1.1-jre:test
[INFO] | +- com.google.guava:failureaccess:jar:1.0.1:test
[INFO] | +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:test
[INFO] | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | +- org.checkerframework:checker-qual:jar:3.8.0:test
[INFO] | +- com.google.errorprone:error_prone_annotations:jar:2.5.1:test
[INFO] | \- com.google.j2objc:j2objc-annotations:jar:1.3:test
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.7.2:test
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | \- org.junit.platform:junit-platform-commons:jar:1.7.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.7.2:test
[INFO] | \- org.junit.platform:junit-platform-engine:jar:1.7.2:test
[INFO] \- org.junit.jupiter:junit-jupiter-params:jar:5.7.2:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.439 s
[INFO] Finished at: 2021-09-19T23:53:58-07:00
[INFO] ------------------------------------------------------------------------
Can you try using these new wrapper modules? They should solve your problem
"
This issue is mainly caused by the fact that users have among their dependencies modules like drools-core and drools-compiler that in reality are no more than "internal implementation details". To avoid similar problems in future, in the very likely case that other modules will be introduced to split engine in finer grained submodules and descope optional features, the following 2 new wrapper modules have been created to cover the 2 different main usage scenarios:
drools-engine aggregating drools-core, drools-compiler and drools-model-compiler
drools-engine-classic aggregating drools-core, drools-compiler and drools-mvel
"
If you want to use the executable model, use drools-engine
Edit:
The dependencies are correct, if you see this error message
InvalidExpressionErrorResult: Method equalsAnyIgnoreCase on class org.apache.commons.lang3.StringUtils with arguments [class java.lang.String, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method intersectionsStartsWith on class com.accolade.clinical.utils.RuleUtils with arguments [interface java.util.List, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method size on class java.lang.Object with arguments [] is missing
It means the executable model is compiling, but it's failing on some of your rules. We'll need a reproducer to see what's going on now. For example the line
InvalidExpressionErrorResult: Method size on class java.lang.Object with arguments [] is missing
Seems really strange as Object doesn't have a size() method.
Please file a bug on issues.redhat.com uploading your obfuscated rules so that we can investigate further.
I've seen in other questions that usually the solution to this warning is to exclude slf4j from the dependency that causes this conflict, but I can't spot the problem in my project.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
I run mvn dependency:tree command and this is the output:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # subscriptionsmanager ---
[INFO] it.pietro:subscriptionsmanager:jar:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.13.1:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.mockito:mockito-core:jar:3.5.13:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.10.15:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.10.15:test
[INFO] | \- org.objenesis:objenesis:jar:3.1:test
[INFO] +- org.mongodb:mongo-java-driver:jar:3.12.7:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- de.bwaldvogel:mongo-java-server:jar:1.11.1:compile
[INFO] | +- de.bwaldvogel:mongo-java-server-core:jar:1.11.1:compile
[INFO] | | +- io.netty:netty-transport:jar:4.1.31.Final:compile
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.31.Final:compile
[INFO] | | | | \- io.netty:netty-common:jar:4.1.31.Final:compile
[INFO] | | | \- io.netty:netty-resolver:jar:4.1.31.Final:compile
[INFO] | | \- io.netty:netty-codec:jar:4.1.31.Final:compile
[INFO] | \- de.bwaldvogel:mongo-java-server-memory-backend:jar:1.11.1:compile
[INFO] +- org.assertj:assertj-core:jar:3.15.0:test
[INFO] +- org.testcontainers:mongodb:jar:1.15.1:compile
[INFO] | \- org.testcontainers:testcontainers:jar:1.15.1:compile
[INFO] | +- org.apache.commons:commons-compress:jar:1.20:compile
[INFO] | +- org.rnorth.duct-tape:duct-tape:jar:1.0.8:compile
[INFO] | +- org.rnorth.visible-assertions:visible-assertions:jar:2.1.2:compile
[INFO] | | \- net.java.dev.jna:jna:jar:5.2.0:compile
[INFO] | +- com.github.docker-java:docker-java-api:jar:3.2.7:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.3:compile
[INFO] | \- com.github.docker-java:docker-java-transport-zerodep:jar:3.2.7:compile
[INFO] | \- com.github.docker-java:docker-java-transport:jar:3.2.7:compile
[INFO] +- org.assertj:assertj-swing-junit:jar:3.17.1:test
[INFO] | +- org.assertj:assertj-swing:jar:3.17.1:test
[INFO] | | \- org.easytesting:fest-util:jar:1.2.5:test
[INFO] | \- org.easytesting:fest-reflect:jar:1.4.1:test
[INFO] \- info.picocli:picocli:jar:4.5.2:compile
The SLF4J bindings warning comes from the Eclipse IDE itself and is not related to your application you write in the Eclipse IDE. So it's just noise that can be ignored (see e.g. here and here).
I guess you have the Eclipse IDE for Enterprise Java Developers with maybe some additional plugins installed. That's more than 900 JARs. SLF4J is used by the Maven support for Eclipse (in the SLF4J bindings warning as m2e) and also by at least one other plugin in an incompatible way causing this warnings. Eclipse is based on OSGi where there is not a flat classpath and where plugins/bundles can be installed, started, stopped and uninstalled at runtime. SLF4J seems not to build with OSGi in mind, hence the misleading warning Class path contains multiple SLF4J bindings, although there is no classpath in OSGi which uses its own class loader instead.
You can solve the issue by adding the following exclusion in the dependencies (of pom.xml) that caused conflict.
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
I don't understand how to load CoreNLP's Shift-Reduce Constituency Parser (SRCP) from my java app.
I'm using Apache Maven to manage my project's dependencies. Per the docs, the SRCP model is not bundled with CoreNLP, so I have downloaded stanford-srparser-2014-10-23-models.jar separately (http://nlp.stanford.edu/software/srparser.shtml) and placed that file in:
~/.m2/repository/edu/stanford/nlp/stanford-corenlp/3.5.2/stanford-srparser-2014-10-23-models.jar
That is the same directory as the core dependency jar
~/.m2/repository/edu/stanford/nlp/stanford-corenlp/3.5.2/stanford-corenlp-3.5.2.jar
Here is the relevant portion of my project's pom.xml:
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
<classifier>models</classifier>
</dependency>
Compiling is successful:
mvn clean compile
But when I try to load the app, I receive:
java.lang.reflect.InvocationTargetException
...
Caused by: edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/srparser/englishSR.ser.gz" as either class path, filename or URL
I unzipped the compiled project war, and "edu/stanford/nlp/models/srparser/englishSR.ser.gz" is not present.
Here is how I'm calling the model in my app:
// Initialize a CoreNLP pipeline
public static Properties props = new Properties();
public static StanfordCoreNLP pipeline;
// Set the CoreNLP pipeline annotators.
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz");
pipeline = new StanfordCoreNLP(props);
How can I update my Maven config to force my CoreNLP dependency to include the srparser model? Keep in mind that I need this configuration to run in other developers' environments, so the solution should be clean and reusable if possible.
Thanks!
EDIT:
In response to #jah's comment, below are the results of mvn dependency:tree. The build succeeds, but the srparser model is not compiled/present:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # [REDACTED] ---
Downloading:
...
[INFO] com.[REDACTED].nlp:nlp:war:0.1.0
[INFO] +- com.strategicgains:RestExpress:jar:0.11.2:compile
[INFO] | +- com.strategicgains:RestExpress-Common:jar:0.11.2:compile
[INFO] | +- com.strategicgains:DateAdapterJ:jar:1.1.4:compile
[INFO] | +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
[INFO] | | +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | +- io.netty:netty-all:jar:4.0.29.Final:compile
[INFO] | +- org.owasp.encoder:encoder:jar:1.1.1:compile
[INFO] | \- com.jcraft:jzlib:jar:1.1.3:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:3.5.2:compile
[INFO] | +- com.io7m.xom:xom:jar:1.2.10: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.1:compile
[INFO] | +- de.jollyday:jollyday:jar:0.4.7:compile
[INFO] | | \- javax.xml.bind:jaxb-api:jar:2.2.7:compile
[INFO] | +- com.googlecode.efficient-java-matrix-library:ejml:jar:0.23:compile
[INFO] | \- javax.json:javax.json-api:jar:1.0:compile
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:models:3.5.2:compile
[INFO] +- org.json:json:jar:20151123:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.4:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.6.4:compile
[INFO] \- commons-io:commons-io:jar:1.3.2:compile
First, download the srparser jar and place it in your project root: http://nlp.stanford.edu/software/stanford-srparser-2014-10-23-models.jar
Second, from the project root, execute the following command to install the srparser model dependency via Maven:
mvn install:install-file -Dfile=stanford-srparser-2014-10-23-models.jar -DgroupId=edu.stanford.nlp -DartifactId=stanford-srparser -Dversion=3.5.2 -Dpackaging=jar
Note the custom artifactId and lack of classifier in the command -- this is to prevent namespace confusion with the other CoreNLP modules.
Third, add the dependency to the Maven project's pom.xml:
<dependencies>
...
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-srparser</artifactId>
<version>3.5.2</version>
</dependency>
...
</dependencies>
Finally, clean install:
mvn clean install
If you continue to experience issues, it may be helpful to clear your Maven dependencies:
mvn dependency:purge-local-repository
And don't forget to add the download/install commands to your project README/environment bootstrap file!
(Thanks for your help #jah and #GaborAngeli.)
To run the shift-reduce parser, you need to include the shift-reduce models jar, which can be found at: http://nlp.stanford.edu/software/srparser.shtml
Not sure if it's on maven, but it appears not?
If you run the mvn command from the folder where the stanford-srparser-2014-10-23-models.jar is placed, then the following command should do the trick.
mvn install:install-file -Dfile=stanford-srparser-2014-10-23-models.jar -DgroupId=edu.stanford.nlp -DartifactId=stanford-corenlp -Dversion=3.5.2 -Dclassifier=models -Dpackaging=jar
When I run "mvn dependency:tree" for my project it shows the following:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # xxxxx ---
[INFO] com.xxx.xxx:xxxxx:war:3.1.0-SNAPSHOT
...
[INFO] +- commons-configuration:commons-configuration:jar:1.5:compile
[INFO] | \- commons-beanutils:commons-beanutils-core:jar:1.7.0:compile
[INFO] +- org.seleniumhq.selenium:selenium-api:jar:2.34.0:test
[INFO] | +- com.google.guava:guava:jar:14.0:test
[INFO] | \- org.json:json:jar:20080701:test
[INFO] +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.34.0:test
[INFO] | +- org.seleniumhq.selenium:selenium-remote-driver:jar:2.34.0:test
[INFO] | | +- cglib:cglib-nodep:jar:2.1_3:test
[INFO] | | +- net.java.dev.jna:jna:jar:3.4.0:test
[INFO] | | \- net.java.dev.jna:platform:jar:3.4.0:test
[INFO] | \- net.sourceforge.htmlunit:htmlunit:jar:2.12:test
[INFO] | +- org.apache.commons:commons-lang3:jar:3.1:test
[INFO] | +- org.apache.httpcomponents:httpmime:jar:4.2.3:test
[INFO] | +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.12:test
[INFO] | +- xerces:xercesImpl:jar:2.10.0:test
>>>[INFO] | | \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.18:test
[INFO] | +- net.sourceforge.cssparser:cssparser:jar:0.9.9:test
[INFO] | | \- org.w3c.css:sac:jar:1.3:test
[INFO] | \- org.eclipse.jetty:jetty-websocket:jar:8.1.9.v20130131:test
[INFO] +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.34.0:test
...
As you see on the marked line, the xml-apis has "compile" scope, and as result it is packed into .war file. Why could it happen?
More interestingly it happens only while Java5 is used, for Java6 the dependency appears as "test".
Maven version: 3.0.4
Study the output of the following Maven command.
mvn -X dependency:tree -Dverbose
That should tell you why Maven upgraded the scope from test to compile.
If you take a look at xercesImpl it contains a dependency to xml-apis:xml-apis:jar:1.4.01:compile with the scope compile so the display of dependency plugin is correct. The usage of -Dverbose will do things as written in the docs:
Whether to include omitted nodes in the serialized dependency tree.
Apart from the above a test dependency as in your case is never being packaged into a war file.
There must be an other source of the same dependency which causes the packaging into the war
Furthermore the change in behaviour in relationship with adding explicit xml-apis to your pom is a supplemental evidence for this.
I had a similar problem.
In my case an entry in the dependencyManagement of a parent pom set the scope of the dependent artefact to compile. Actually I omitted the scope tag which effectively is the same as setting it to compile. Changing it to provided helped.
Seems the scope in dependencyManagement takes precedence over the transitive scope. Which makes sense but can still cause confusion when all you wanted to do is define the version.
It was actually not hard to spot: Looking at the effective-pom showed the dependencyManagement entry.
I am using Apache Poi version 3.8 in my POM. But it is still downloading poi-3.2 along with poi-3.8 as (may be) due to some internal dependency. The strange behavior for me is My project using poi-3.2 when even I have mentioned 3.8 version in POM. I have Googled a lot for the same, but found myself unlucky.
Here is my POM entry :
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
<type>jar</type>
</dependency>
I have checked the poi jar my project using in classpath by the code:
ClassLoader classloader =
org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
"org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
System.out.println("Core POI came from " + path);
This prints :
Core POI came from file:/D:/Software/Softwares/apache-tomcat-6.0.33/webapps/scd-web/WEB-INF/lib/poi-3.2.jar!/org/apache/poi/poifs/filesystem/POIFSFileSystem.class
There is a poi-3.8.jar in same folder but classpath picking up 3.2.
My question is :
What should I do to so that My project uses poi-3.8.jar instead of poi-3.2.jar.
Many Thanks !!
Edited:
Output of mvn dependency:tree
[INFO] Building SCD-common [INFO] task-segment: [dependency:tree]
[INFO]
------------------------------------------------------------------------
[WARNING] While downloading xmlbeans:xmlbeans:2.3.0 This artifact has been relocated to org.apache.xmlbeans:xmlbeans:2.3.0.
[INFO] [dependency:tree] [INFO] com.idc:scd-common:jar:4.2.0.5
[INFO] +- org.springframework:spring-webmvc:jar:2.5.6:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | +- org.springframework:spring-beans:jar:2.5.6:compile
[INFO] | +- org.springframework:spring-context-support:jar:2.5.6:compile
[INFO] | \- org.springframework:spring-web:jar:2.5.6:compile
[INFO] +- com.idc.worldwide.keystones:service-single-signon-dynamo-api:jar:1.0:compile
[INFO] +- com.idc.worldwide.keystones:service-single-signon-dynamo-database-impl:jar:1.0.3:compile
[INFO] | +- org.apache:commons-dbcp:jar:1.2.2:compile
[INFO] | +- org.apache:commons-pool:jar:1.4:compile
[INFO] | \- com.idc.worldwide.webchannel:sage-core:jar:3.2.0.001:compile
[INFO] | +- com.idc.webchannel.legacy.sage-dependencies:aspose-slides:jar:1. 0:compile
[INFO] | +- com.servlets:cos:jar:09May2002:compile
[INFO] | +- com.sun:jai_codec:jar:1.1.3:compile
[INFO] | +- com.sun:jai_core:jar:1.1.3:compile
[INFO] | +- com.verity:k2:jar:5.00.3177.0:compile
[INFO] | +- org.apache:poi:jar:3.2:compile
[INFO] | +- org.apache:poi_contrib:jar:3.2:compile
[INFO] | +- org.apache:poi_scratchpad:jar:3.2:compile
[INFO] | \- org.springframework:spring:jar:2.5.6:compile
[INFO] +- org.springframework:spring-core:jar:3.0.5.RELEASE:compile
[INFO] | \- org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
There are various mvn command to help solving this issue:
mvn dependency:analyze-dep-mgt
will print details about dependency resolving.
mvn dependency:tree
will print the dependency tree (very helpful to see dependencies of your dependencies)
mvn help:effective-pom
will print the pom resulting from the merge of your pom hierarchy.
If you don't find any references to poi-3.2 with maven, you can take a look at your classpath in your IDE. Do you add any jar by-passing maven ?
Editing your question with the result of those commands can be useful for us to help you.
Looks like
org.apache:poi:jar:3.2
is a compile dependency of
com.idc.worldwide.keystones:service-single-signon-dynamo-database-impl
(although I think you may have cut something)
and
org.apache.poi:poi:jar:3.8
is not a dependency (it's not in the dependency tree).
Make sure your <dependency> entry is within the <dependencies> tag.
Run
mvn dependency:tree
to check which library has a transitive dependency to poi 3.2. You can then exclude it in your pom.
<dependency>
<groupId>sample.group</groupId>
<artifactId>sample-artifactB</artifactId>
<version>1</version>
<exclusions>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</exclusion>
</exclusions>
</dependency>
Maybe you are mixing normal dependency with plugin dependency, see here (not too fitting answer).
Use dependency management in the root POM if you have child projects.