IntelliJ : how to verify log4j2.xml is on the classpath? - spring-boot

I'm working on a spring boot/maven project that I created with SpringIntializr. If I add all the necessary dependencies to my pom, and if I add my log4j2.xml to MyApp/src/main/resources,
and if after a build I see my log4j2.xml file in MyApp/target/classes, does that mean that the log4j config has been successfully added to the classpath?
I asked a more comprehensive question here, but thought this issue might merit a standalone question

Basically yes, what gets to the classes, later on, gets handled by the spring-boot maven plugin and should be available in the artifact that you build.
At this point it doesn't really matter whether it was originally in the src/main/resources folder or not.
Having said that, log4j2 is not used by spring boot by default (it uses logback), so you should set it up
For such a setup see this example

Related

why are the github projects of spring-boot-starter projects empty?

On looking at the spring-boot-starter-web, spring-boot-starter-security projects on github, i find them to be empty with just a build.gradle file present there.
I hope this is as expected, but this leads me to understand where the actual source code can be found. And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
I hope this is as expected
This is as expected. Spring Boot's starter modules exist purely to being multiple dependencies together into a convenient "package". For example, if you want to write a Servlet-based web application using Spring MVC and Tomcat, a single dependency on spring-boot-starter-web provides all of the dependencies that you need. You can learn a bit more about the starters in the reference documentation.
Where the actual source code can be found
The majority of the code can be found in spring-boot-autoconfigure. For more production-focused features, you'll also find some code in spring-boot-actuator-autoconfigure. The code in these two modules is activated automatically when the dependencies that it requires are on the classpath. You can learn more about this conditional activation and auto-configuration in the reference documentation.
And I use maven, so I was expecting atleast a pom.xml in these projects. But since it is not present, I am wondering how spring boot team publishes there artifacts to maven central repo.
Spring Boot is built with Gradle which, unlike Maven, completely separates the configuration needed by the build system to build the project and the information needed by a build system to consume the project. The build.gradle files provide all of the information that Gradle needs to build the project. As part of this, it generates Gradle module metadata files and Maven pom.xml files that contain all of the information needed to consume the project with Gradle and Maven respectively. These generated files are then published to Maven Central alongside the jar files, source code, etc.

StatusLogger Unable to locate a logging implementation, using SimpleLogger. MavenEJBModule in an EAR

I am fairly new to java and classpaths..
I have an EJB project which has a dependency on log4j2 in it's POM. It runs within an EAR and therefore is an EJBModule within the EAR POM. I also have a parent POM which both the EAR and the EJB project derive from. I am getting the error "StatusLogger Unable to locate a logging implementation, using SimpleLogger" when attempting to retrieve the logger using the LogManager. My log4j2.xml file sits in the src/main/resources folder of the EJB Project.
I have tried putting the log4j2.xml in the root of the project, and in the EAR. I have tried putting the log4j2 core and api dependecies in the EAR and in the parent POM. I have tried changing the manifest.mf file to include log4j. But none of these things have worked.
I also noticed that the "java.class.path" returns jboss-modules.jar. What does this mean? In my War modules this is different.
I need to know how I can use Maven to provide the log4j jars to the EJBmodule.
Thanks,
Jen
Someone else recently raised a similar issue on the log4j-user mailing list. I believe it was eventually tracked down to a JBoss issue. AFAIK, this is not resolved yet. Raising this issue to the JBoss team may speed up resolution.

Skinny war and log4j

We are using log4j for application logging and maven for application packaging.
As we have 3-4 application being deployed as a part of an EAR the size of the EAR is large.
We were trying to go with the 'Skinny War's' approach but faced a problem with log4j. We used to log application logs in different file for each application but with Skinny WAR's as the classes of log4j are being loaded only once, only one log file is being created and log of each application is being appended to the same log file.
We thought of the famous solution of packaging log4j.jar in each WAR but then we'll have to move every jar file which needs the log4j in WAR ex. spring jar's this essentially will increase the EAR size.
Is there any alternate solution to this problem ?
Any suggestion would be a great help.
Thanks.
Resolved the issue with RepositorySelectors.
Check this
see if log4j 1.3 / log4j2 helps you fix the init - google ContextJNDISelector
http://logging.apache.org/log4j/2.x/manual/webapp.html
To compare
logback - JoranConfigurator it does exactly that, custom context based config
http://logback.qos.ch/manual/configuration.html

Maven: Managing Spring configurations

I have several set's of Spring configurations (XML files for bean initialization and properties files), for different kind of services/servers. I've also use maven to manage the dependencies and build (alternating with eclipse).
My intent was to have a flag I could pass to maven to build the project with a selected configuration profile.
Example:
mvn package production
will put the conf/production files in WEB-INF/classes
I've solved the problem by using the approach of Spring profiles as suggested by #gerardribas.
I've looked at the Jhipster implementation and follow that way. If somebody is following the same path, be aware that your need to upgrade your servlet version to 3.x.

Spring annotation configuration does not find directories/classes in JARs

I have the same problem as these guys:
Spring Annotation-based controllers not working if it is inside jar file
http://forum.springsource.org/showthread.php?t=64731
...but the difference is that I use Maven 2 as a build tool.
How do I achieve the same effect using Maven 2?
I saw this solution to creating a classpath entry in the manifest, but it generates a lot of absolute links to JARs which wouldn't make sense in my production environment:
Maven - how can I add an arbitrary classpath entry to a jar?
Maven 2 generates the directory entries, which is the answer to this question.

Resources