I'm trying to run
mvn exec:java .....
then it uses the runtime classpath defined by my pom, which I think defaults to the compile classpath. the problem is that I found that my src/main/resources/log4j.xml is not reflected, since I put DEBUG logging in the file, but I only see WARN in the output.
I suspect that it's actually the log4j.xml from some of the dependency jars that is being used.
so I need to elevate the src/main/resources/log4j.xml to the front of my compile/runtime classpath. but how do I specify the relative order of src/main/resources vs dependency jars in the classpath?
Thanks
Yang
One workaround is to explicitly specify the log4j.xml that you want log4j to use using a command-line argument.
-Dlog4j.configuration=file:/log4j.xml
Related
I have a rest service running on dropwizard. Dropwizard requires slf4j to be configured with logback. When launching this service directly from my maven project in eclipse, the service starts up with the proper logback binding. When I do a maven package with the maven shade plugin, however, the resulting jar is still pulling log4j onto the classpath, which is resulting in slf4j choosing org.slf4j.impl.Log4jLoggerFactory instead of the logback binding.
I have made sure to exclude every transitive instance of log4j in my pom, as well as slf4j-log4j12 (mvn dependency:tree shows neither of these in my hierarchy), yet somehow it still always shows up in my uber jar after running mvn clean package.
How can I figure out what is causing log4j to always exist on my classpath?
I am using WildFly 8.2.1.
I need to add specific JAR files to the class path. How can I do that?
Do I need to get inside the module hell?
All I need is to add a couple of extra Oracle JAR files to enable using TLS on the data source connection...
When you build your .war file, add them to the /WEB-INF/lib directory. They will be accessible on the classpath from there. In eclipse the eclipse maven plugin, m2e, will do it by reading your POM file, or of course, maven run by hand will do it.
In the POM file, have it packaged as a war
<packaging>war</packaging>
and declare your jar as a dependency.
I have an issue with logging in a maven plugin for my applicaton. The maven plugin uses log4j with slf4j as facade, and I have configured (in the plugin) a special file logger for outputs.
When I run my plugin application (local, not as a plugin), the output is written to the file as intended.
However, when I use the maven plugin in another project and build it with mvn clean install, the output is only on the console. It seems not to be a problem of configuration as I do find my logger and (file-)appender.
My assumption is that maven absorbs the slf4j output to display it on its own console. Can anybody confirm or determine this respective tell me how to fix it? I appreciate any help.
It would be helpful to see your actual POM file. However, there are a few potential problems that I know about.This dependency is required because the
The maven-javadoc-plugin:2.10.3 has a dependency on maven-core:2.2.1, which has direct or indirect dependencies on sl4j-nop:1.5.3 and slf4j-jdk14:1.5.6. I introduced a dependency on maven-core:3.3.9, which didn't have this problem. The artifact maven-javadoc-plugin:2.10.3 also has a dependency on log4j:log4j. I placed an exclusion on the dependency for maven-javadoc-plugin so that it didn't include log4j:log4j.
See https://bradleyaross.wordpress.com/2016/05/05/java-logging-frameworks/ and the referenced GitHub libraries, especially the pom.xml files for the parent module and tutorials-common.
Trying to avoid the use of jargon, so that I don't get misinterpreted.
Here is the scenario, My project requires a jar in order to get compiled(let say x.jar). My project get once compiled gets converted into a WAR file, which gets deployed somewhere.
Now I want x.jar just to be there for my project to compile and it should not be packed(or part of) inside WAR file.
How can I do this in Maven ? should I used dependency scope as "provided"
You are right, as stated in the Maven FAQs, the scope to use is provided,
How do I prevent including JARs in WEB-INF/lib? I need a "compile only" scope!
The scope you should use for this is provided. This indicates to Maven that the dependency will be provided at run time by its container or the JDK, for example.
Dependencies with this scope will not be passed on transitively, nor will they be bundled in an package such as a WAR, or included in the runtime classpath.
To quickly try it out, you can use
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp
to generate a "toy webapp" project, add a dependency to your project and set it to <scope>provided</scope>.
I'm looking for a way to modify the class path in maven. Why?
I want to instrument maven artifacts without corrupting the local repository such that when surefire-tests run it will see the instrumented classpath, not the original class path.
In general maven manages the classpath by itself.
Having said that, there are a couple of options you can try here:
You can use 'additionalClassPath' parameter in surefire plugin. You can read about ithere:
You can generate your instrumented jars and use them in scope test, don't use un-instrumented jars in the tests at all
Hope this helps