What are the pom.xml and log4j.properties under Apache CXF for? - apache

I am new to Webservices and I need to know what the pom.xml and log4j.properties files are for in an Apache CXF project. I read the POM is used to represent a Maven project so it holds configuration files, dependencies etc. Is that correct? Why would I use Maven bulid instead ob sinpl runnig it as a Java application. And what is the .properties file for?
Thanks for any help.

You are correct about the POM file. It is a "Project Object Model" that holds the configuration files, dependencies. I use it because you can do a mvn clean install, instead of doing it separately, it splits the code into modules, dependency-relationships and versions.
log4j.properties is an open source API that is used to specify where you want your logs to be redirected. For example:
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
will make all your logs be output in the console.
If you want it to be saved in a file, use:
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

pom.xml is used to build (ex. create .jar files) the project using Maven. It it not used at runtime.
log4j.properties is a runtime configuration, that defines what logging information should be written and where. Check out these examples: http://www.mkyong.com/logging/log4j-log4j-properties-examples/

Related

Sonar properties file - ignoring doesn't work

Issue: I am trying to set the sonar-project.properties to ignore a module or a package and it doesn't work.
I am totally new to Sonar and I'm using the eclipse plugin on a java maven project and I'm trying to ignore stuff (e.g. a package or a module) but the sonar-project.properties file doesn't seem to have any effect.
I have only one properties file in the root of my project. And there are 2 modules (one for java and one for webapp)
sonar.projectKey=projectname
sonar.projectName=projectname
sonar.projectVersion=1.0
sonar.modules=javamodule,webapp
sonar.sources=src/main/
sonar.tests=src/test/java
sonar.java.binaries=target/classes
sonar.java.libraries=../*/target/**/*.jar
If I try to exclude something like
sonar.exclusions=com/package/files/**/*
or
webapp.sonar.exclusions=resources/**/*
then I do analyze on the module and nothing was ignored. I also tried adding individual properties files inside the modules..
Also, I would like to ignore the whole webapp module. Should I just not declare it, or is there some other way?
Edit:
For example's sake, this is my package structure
javamodule
- src/main/java
- com/package/files
- src/main/resources
- src/test/java
- src/test/resources
webapp
- src/main/resources
- src/main/webapp
The SonarQube Eclipse plugin only takes into account exclusions set through the web interface. It doesn't take into account exclusions set in configuration files such as sonar-project.properties files.

log4j collision with multiple ejb containers

I have implemented several Java applications stored in EJB containers which I deploy on the same Glassfish domain. Each of them has it's own log4j.properties file located in the resources folder of each's application project (they are all Maven projects).
A different log file is configured in each log4j.properties file but when I deploy my applications they end up to write in the same log file.
Does anyone know how to resolve this problem? :)
EDIT: Here are my log4j.properties files for two projects.
The first:
log4j.rootLogger=ALL,AppFileAppender
log4j.appender.AppFileAppender=org.apache.log4j.FileAppender
log4j.appender.AppFileAppender.File=${com.sun.aas.instanceRoot}/logs/Engine.log
log4j.appender.AppFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.AppFileAppender.layout.ConversionPattern= %d [%t] %-5p %c - %m%n
log4j.logger.hesemulatorproducer=ALL,AppFileAppender
log4j.logger.org.hibernate=info
The second:
log4j.rootLogger=ALL,AppFileAppender
log4j.appender.AppFileAppender=org.apache.log4j.FileAppender
log4j.appender.AppFileAppender.File=${com.sun.aas.instanceRoot}/logs/SendEndDeviceEvents.log
log4j.appender.AppFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.AppFileAppender.layout.ConversionPattern= %d [%t] %-5p %c - %m%n
log4j.logger.hesemulatorproducer=ALL,AppFileAppender
I cannot see comment link for this question. So I am asking few clarifications in this answer. These may help in finding root cause of the issue.
Can you please check the config file path and name, you specify while initializing Log4j?
Also, can you please give the file in which log is being printed for both projects? Is it server log or one of the application log file?
Are these projects being deployed in different WARs/EARs?
You can print repository location using org.apache.log4j.LogManager.getLoggerRepository().

Apache Ivy Best Practices

Hi I'm reading up on Ivy for the first time and had a few quick questions:
Need confirmation: the IvyDE plugin is used to configure just the ivyconf.xml file for all workspace projects, correct?
Where does this ivyconf.xml live? I'm running Windows 7 and can't find this hidden .ivy directory anywhere!
Where do you usually place a project's ivy.xml and other xml config files?
Thanks for any nudges in the right direction!
IvyDE allow you to resolve dependencies per project. You could use separate ivyconf.xml in different projects.
You could place ivyconf.xml (or ivysettings.xml) where you want. You could use one per project (as I do) or one for all projects (as I did before).
Usually I put ivy.xml beside Ant's build.xml in the root of my project. But ivysettings.xml I put in project/etc/ivysettings/ directory.
My team uses a separate build project in Eclipse that stores the ivysettings.xml file. The IvyDE plugin provides the Ivy dependency container that the Java projects can use. IvyDE can optionally allow inter-project dependency resolution, but this is off by default.
I'd suggest changing the order of classpath entries in the Ivy Classpath configuration to lexical, otherwise it shows dependencies in the order of the ivy.xml file.
Each project should have their own ivy.xml file - we also follow the same pattern as Alexey uses of using the project's top-level directory.
I've never used an ivyconf.xml file - a quick google suggests this is an alternative (older, deprecated?) name for the ivysettings.xml file.
You will need to write your own ivysettings.xml file to tell IvyDE where your repositories are and which resolvers to use. Leave a comment if you're interested in an example ivysettings.xml file.
Which repositories are you using? Maven Central? Setting up your own repository with Nexus, Artifactory or just using the file system?

ivy: prevent downloading sources and .txt files

How to tell IVY to not download source and .txt files. I have a dependency and it downloads license.txt files with it, when i use soemthing like this
<ivy:cachepath pathid="ivy-src-classpath" conf="compile"/>
it put the .txt files in the classpath which errors out while using java task
Unable to obtain resource from /home/muthiah/Work/ivy/cache/org.apache.commons/com.springsource.org.apache.commons.logging/licenses/license-1.1.1.txt: java.util.zip.ZipException: error in opening zip file
In your ivy.xml file add a configuration mapping to the other module's "default" configuration:
<dependency org="commons-lang" name="commons-lang" rev="2.5" conf="compile->default"/>
Without this mapping you're retrieving both the default and optional dependencies of the remote module.
Another good mapping (for Maven modules) to use is:
conf="compile->master"
This will retrieve the remote artifact without it's transient dependencies.
I had the same issue with multiple java.util.zip.ZipException: error in opening zip file in my ANT output logs, because there were licence .txt files in the classpath. The solution for me was to update the ivy:cachepath entry by adding type="jar":
<ivy:cachepath pathid="ivy-src-classpath" conf="compile" type="jar"/>
This will restrict only jar files to be added to the classpath.

Standard maven layout for a web application, do my .properties files go?

Assuming I have a .properties file and hibernate.cfg.xml in a standard maven web application layout where should they be placed so that they are included in my .war file when I run package?
src/main/resources
src/main/java
src/main/webapp
src/main/config
?
Application/Library resources go in src/main/resources (they will end up in target/classes first after compilation and then in WEB-INF/classes in the war after packaging).
See also
Introduction to the Standard Directory Layout