I am attempting to create a program in Java using Netbeans. I am attempting to use org.slf4j. I think I have placed the sufficient amount of slf4j jar files in my CLASS PATH. I have placed slf4j-api, slf4j-jcl, slf4j-jdk14, slf4j-nop and slf4j-simple in my class path.
My question is: Am i placing the wrong jar files in my class path, the Zip file for the slf4j folder included a large amount of jar files. Why are there so many executable jar files included for SLF4J.
Ultimately, the program needs to compare 2 pdf files at a time and spit out an error message if the files are different. Would anyone know if there is anything out there that I can include so I don't have to deal with this SLF4J package.
Below is where I am attempting to run the package.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Set Dependencies as follows.
In Maven
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>version number</version>
</dependency>
In Gradle
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: 'version number'
}
In Gradle add the following dependencies:
implementation 'org.slf4j:slf4j-api:1.7.28'
implementation 'org.slf4j:slf4j-simple:1.7.28'
The last one dependency needs to be added to Resolve "Failed to load class org.slf4j.impl.StaticLoggerBinder"
In build.gladle ( the second one ) look at dependencies and add this line:
dependencies {
...
implementation 'org.apache.directory.studio:org.slf4j.api:1.7.2'
}
Related
I had a Java 8 project and my configuration file was in resource folder and everything worked fine. Now I switched to Java 9, added requirement for log4j.api, and configuration file cannot be found anymore.
Do I need to add something else in my module-info file for the logger to find it's config?
For now, it's like this
module project.main {
requires jdk.incubator.httpclient;
requires jackson.databind;
requires jackson.core;
requires jackson.annotations;
requires log4j.api;
}
The Project structure is as:
The build.gradle file is as:
The log4j~faq suggests using at least log4j-api-2.x and log4j-core-2.x. Preferably add these to your build.gradle file:
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.9.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.9.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.9.0'
And make sure conflicting dependencies are excluded
In the module-info.java further you shall update(this is what I did in a custom maven project)
requires log4j; // not log4j.api
It should work for you then with the same directory structure as well.
Hint: This is where I started debugging it from.
Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?
This occurs when the default configuration files log4j.properties and
log4j.xml can not be found and the application performs no explicit
configuration. log4j uses Thread.getContextClassLoader().getResource()
to locate the default configuration files and does not directly check
the file system...
Placed a debug point in the ClassLoader#getResource method and just keep an eye of resources looked for by the library.
Also to bring up the point over resources like resources/foo/bar/log4j.properties as stated in the release notes in JDK-8142968
JDK internal resources, other than class files, in the standard and JDK modules can no longer be located with the
ClassLoader.getResourceXXXAPIs. This may impact code that relies on
using these APIs to get at JDK internal properties files or other
resources.
and seconded by the java-doc of ClassLoader#getResource as well:
Resources in named modules are subject to the encapsulation rules
specified by Module.getResourceAsStream. Additionally, and except for
the special case where the resource has a name ending with ".class",
this method will only find resources in packages of named modules when
the package is opened unconditionally (even if the caller of this
method is in the same module as the resource).
I have a java gradle project. I have a dependency.
dependencies {
compile project(":mymodule")
compile 'org.springframework:spring-context:4.1.2.RELEASE'
}
Where can I find and use exact jar file name of both my custom module and spring dependency jar to process it further in composing application's libs, folders, etc?
Stick this in a new task:
project.configurations.compile.each{ println it}
Or, for just one specific dependency:
println project.configurations.compile.find {it.name.startsWith("something") }
However, if you're looking to create distributable packages including dependencies, you really should look into the gradle application plugin.
I am using "ch.qos.logback" % "logback-classic" % "1.1.7" as a dependency (in my scala+sbt project) and using the logger: val internalLogger = LoggerFactory.getLogger(this.getClass)
and I am getting the following error:
[error] missing or invalid dependency detected while loading class file 'Logging.class'.
[error] Could not access term classic in package ch.qos.logback,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'Logging.class' was compiled against an incompatible version of ch.qos.logback.
[error] one error found
The error is general and unclear. Any ideas where things might be going wrong?
You missed to add the jar files.
If you are using maven then add the following dependency in pom.xml
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
If you use gradle, then add it in dependencies section in build.gradle file:
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.0.13'
Resource Location:
Logback configuration
In a multi-module sbt project, the logging dependency was not being properly used by one of the modules. I had to add the dependency to the root module.
I keep getting this error.I've included the hadoop commons and the core libs in the classpath but still i keep getting this error.Help would be highly appreciated
Here's how to troubleshoot: Look inside the jar that you're executing to see if that class file is actually there:
jar tvf target/my-jar-with-dependencies.jar | grep hadoop/conf/Configuration.class
If it's not, you need to add it to your classpath or change the way your jar is packaged.
Are you using Maven or some similar build tool? You may have a dependency with a 'scope', which means that it will only be compiled into your jar in certain circumstances.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
</dependency>
In this example, the scope tag tells Maven that you're using this dependency for building, but it indicates that the dependency will be provided during runtime, so you'll either need to remove this tag or add the hadoop jar using -cp=/path/to/jar.jar during runtime. Another example of a scope like this is 'test', which indicates that the jar is only needed in the path during unit tests.
make sure the classpath in your jar. You can check it like mark said;
jar tvf target/my-jar-with-dependencies.jar | grep hadoop/conf/Configuration.class
add dependency to hadoop-core.
I am having a problem setting up the classpath for slf4j for compiling java files.
I tried two ways:
1. provide the classpath in command line
javac -cp /Users/page/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar src/main/java/com/scg/domain/*.java src/main/java/com/scg/util/*.java
This gave the following error:
src/main/java/com/scg/util/ListFactory.java:8: error: package org.slf4j does not exist
import org.slf4j.Logger;
^
src/main/java/com/scg/util/ListFactory.java:9: error: package org.slf4j does not exist
import org.slf4j.LoggerFactory;
...../long error message
I tried to export the CLASSPATH to my env variable.
export CLASSPATH=/Users/page/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar
This did not help either and resulted in same error, when I tried
javac src/main/java/com/scg/domain/*.java src/main/java/com/scg/util/*.java
I am trying to compile all the java files in two packages. but I need to have slf4j in my classpath. but somehow I am not able to get it work.
Thanks
This dependency is the api:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
You need the slf4j-api.jar in your classpath for compiling, not the slf4j-log4j12.jar.
It worked in maven because the binding-lib (slf4j-log4j12) has a dependency on the api and thus maven loads that as well, without you explicitly defining it as a dependency.