In my current project we are using log4j as logger, but as per enhancement we have to migrate to log4j 2. we are using gradle as project dependency tool. so anyone can please tell me is there any way to bridge the slf4j-log4j 2 in build.gradle file like we are doing in maven
In your build.gradle change this line
compile 'org.slf4j:slf4j-log4j12:1.7.7' //or similar one
with does two:
compile "org.apache.logging.log4j:log4j-slf4j-impl:2.0-beta9"
compile "org.apache.logging.log4j:log4j-core:2.0-beta9"
it worked for me.
Remember that format and name of log4 configure file has changed
Related
How do I add a the JAK Library to my java project so I can use it?
I Dont understand how to I acctually make it useable in my Java Porject if it is on Gittub and I dont see the Jar Files.
Can Anyone please help me with a little guidance? I've checked online and 0 videos about it so All I can ask is help from you guys.
Adding jar dependencies to a Java project depends on what build tools are used (e.g. Maven, Gradle, Ant, etc.). If you're using an IDE, the project can be created around the build artifact (pom.xml for Maven projects, build.gradle for Gradle, etc.) or explicitly add jar files to the CLASSPATH for that project.
If you have a Maven project, add this dependency to your pom.xml file:
<dependency>
<groupId>de.micromata.jak</groupId>
<artifactId>JavaAPIforKml</artifactId>
<version>2.2.1</version>
</dependency>
For Gradle project, add this to your build.gradle file:
dependencies {
compile group: 'de.micromata.jak', name: 'JavaAPIforKml', version: '2.2.1'
//...
}
Alternatively, you can manually download the jars from the official dev.java.net Maven 2 repository. Note that JAK depends on JAXB libraries so you will need them also. Review the POM for JAK for details.
I opened the restbucks project with Intellij. I have lombok plugin installed, annotation processing enabled. I am using javac compiler in Intellij settings. I have lombok.config in project root like in git repository, I also tried copying it to src/main/java and src/main/resources but no matter what I try, when I build the project with Intellij, after posting an order, I get:
Argument #0 of constructor [constructor for
org.springsource.restbucks.order.Order, annotations: {interface
com.fasterxml.jackson.annotation.JsonCreator=#com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)}]
has no property name annotation; must have name when
multiple-parameter constructor annotated as Creator
Seems like lombok.anyConstructor.suppressConstructorProperties=true has no effect. When I build with maven then it works fine.
When I delete the lombok.config file, Intellij starts showing errors all over the project so the file seems to be recognized by Intellij afterall. But the build doesn't run as expected as posting to orders fails as mentioned above. Does anyone know what's going on here?
Lombok plugin does support lombok.config file.
The lombok.anyConstructor.suppressConstructorProperties is deprecated as per in Lombok doc
BREAKING CHANGE: lombok config key lombok.anyConstructor.suppressConstructorProperties is now deprecated and defaults to true, that is, by default lombok no longer automatically generates #ConstructorProperties annotations. New config key lombok.anyConstructor.addConstructorProperties now exist; set it to true if you want the old behavior. Oracle more or less broke this annotation with the release of JDK9, necessitating this breaking change.
Use the new lombok.anyConstructor.addConstructorProperties in the lombok.config located in the root folder and
also, perform a clean install and then should be fine.
Can jrebel detect a jar file has been added to maven/gradle and then automatically add it my libs folder and add it to the classpath?
For example I'm running IntelliJ and Jetty and I make a gradle change to add a new version of a jar dependency and then click "gradle refresh."
Can jrebel be set up to load that jar? Otherwise this requires a full restart which partially makes jrebel less useful.
The short answer is no.
JRebel works by reloading individual class files, but not whole JARs.
If you add a new dependency or update the version of an existing dependency then it won't get reloaded.
However, if this library you're updating or adding is your own internal library that you build yourself, then it is possible to reload the changes.
In that case you need to build a rebel.xml file into the root of that library jar and configure it to point to the build directory of the library.
I'm migrating a bunch of our webapps (run in Jetty) from log4j to slf4j. Previously, log4j would find the log4j.properties file from jetty.home/resources/log4j.properties. After moving to slf4j, the external log4j.properties file is not found and everything is getting logged to stderror.
If I build the same log4j.properties file inside the war, everything works as expected (and as it did previously). What am I doing wrong? I'd like to use an external logging config in jetty.home/resources as opposed to building it into the war.
In each webapp war, I have log4j-1.2.17, slf4j-api-1.7.10 and the binder slf4j-log4j12-1.7.10.
The Jetty start.ini is OPTIONS=Server,jmx,resources,websocket
I was able to resolve this by adding the -Dlog4j.debug java option to the start-up script. In doing so, I found that log4j was picking up a log4j.properties file from within the war that had been added for test.
The two options I found for fixing this were either remove the embedded config file, or add a start-up option. I was able to move module's log4j file to it's root so that it was excluded from the maven build. This way, it is still available locally (for test) but not built into the war.
The other option that worked was to add -Dlog4j.configuration=file:resources/log4j.properties
to the start-up options. This approach seems a bit convoluted but will override the embedded file.
Assuming all my Gradle plugin user going to have a MYAPP_HOME sys variable set in there system
in MYAPP_HOME page i have a jar at $MYAPP_HOME/lib/mylib.jar
i am writing my own plugin....
I can find the MYAPP_HOME variable is set and fine the jar exists..
How can i add this jar dependency in my custom gradle plugin... ? when user runs my plugin say compileMyplugin my custom gradle plugin need to set the $MYAPP_HOME/lib/mylib.jar jar as compiler dependent
How to do this any one help me ?
The plugin just needs to do:
project.dependencies {
compile project.files("${System.getenv("MYAPP_HOME")}/lib/mylib.jar"))
}
PS: In general, I wouldn't recommend relying on an environment variable and the availability of a Jar on the local file system. Instead, I'd publish the Jar to an artifact repository or put it under source control.