Where do I configure jarsToSkip option when using tomcat7-maven-plugin - java

Im using maven with tomcat7-maven plugin and its working quite well. Recently I noticed a message saying
At least one JAR was scanned for TLDs yet contained no TLDs.
Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them.
So I did some reasearch and realised I need to set the jarsToSkip property for the jars that dont contain TLDs. I have been looking into how to find which jars it is that is causing the problem but with little luck it seams tomcat7-maven-plugin is nott passing my loggersettings that are required for output of names of the jars.
Also I do not know where I set the jarsToSkip property when I have found the jars.
Any help would be appreciated.

Believe the property jarsToSkip is a "catalina.properties" entry. Where ever your Tomcat conf folder is look at file "catalina.properties" and you should see a property like this around line 90 or so:
tomcat.util.scan.DefaultJarScanner.jarsToSkip=\
You should be able to add jars to that list to prevent them from being scanned.
As far as finding which jars are causing the issues, that would be a little more difficult to determine. Probably some trial and error work to be done there.

When using the Tomcat 7 Maven Plugin, anything you would otherwise have put in catalina.properties can go in your plugin config. i.e.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<useTestClasspath>true</useTestClasspath>
<path>/</path>
<systemProperties>
<tomcat.util.scan.DefaultJarScanner.jarsToSkip>
myjar.jar
</tomcat.util.scan.DefaultJarScanner.jarsToSkip>
</systemProperties>
</configuration>
</plugin>

There seems to be a bug with the maven tomcat plugin prior to 2.2 (ie 2.0) where the <systemProperties> don't seem to be propagated. Also in 2.2 a config option called<jarScanAllDirectories> was added which seems to improve performance even more (I think it ignores WEB-INF/classes).
Ignoring port and path I found the following configuration to greatly improve Maven Tomcat performance.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>9090</port>
<path>/</path>
<jarScanAllDirectories>false</jarScanAllDirectories>
<systemProperties>
<org.apache.catalina.startup.ContextConfig.jarsToSkip>*.jar</org.apache.catalina.startup.ContextConfig.jarsToSkip>
<tomcat.util.scan.DefaultJarScanner.jarsToSkip>*.jar</tomcat.util.scan.DefaultJarScanner.jarsToSkip>
</systemProperties>
</configuration>
</plugin>

There is this open bug # https://github.com/psi-probe/psi-probe/issues/348
Just pointing out.

Related

Maven resource plugin doesn't filter out customized delimiters nested in ${}

I have a properties file:
property.a=$[value]
I am using maven-resources-plugin with filtering on this property file enabled in order to substitute build variables in there:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>$[*]</delimiter>
</delimiters>
</configuration>
</plugin>
Everything works flawlessly, until $[*] token is not nested into ${*} one, like below:
property.a=${VALUE:$[value]}
Assuming value=XXX in Maven properties, I expected to get:
property.a=${VALUE:XXX}
However, Maven resources plugin doesn't substitute $[value] in there, leaving filtered contecnts as-is. I tried enabling supportMultiLineFiltering but it changed nothing. It feels like despite <delimiters> option is set explicitly, plugin treats ${*} as a valid delimiter either, and tries to filter it, without success.
How should I configure maven resources plugin so that it filters the property file contents as expected?
I just realized I missed a configuration option in maven resource plugin, designed specially for controlling default delimiters - useDefaultDelimiters, which is true by default. The configuration below solved the issue:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>$[*]</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>

Share Classloader between multiple in Jetty Maven Plugin

I'm try to configure maven jetty plugin to start my war application, but it has some complications like as follow descriptions:
1º - It has dependencies with a ejb jar;
2º - It has dependencies with war (tag jstl:import context="nscl");
3º - The classloader between wars must be shareded.
So, I need some help to resolve the third problem. Looks my jetty plugin configuration in pom.xml:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.1.v20170120</version>
<configuration>
<useProvidedScope>true</useProvidedScope>
<useTestScope>true</useTestScope>
<webApp>
<contextPath>/nscl/cntr</contextPath>
</webApp>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<war>${contexto.war.path}</war>
<contextPath>/nscl</contextPath>
</contextHandler>
</contextHandlers>
<systemProperties>
<systemProperty>
<name>spring.profiles.active</name>
<value>test</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
The problem is, when jetty is starting the second war (context-path = nscl), I receive problems saying the classes used to start first war not exist to second, a sample is classes of spring framework.
Thanks !!!!
You are hitting Standard Servlet Spec behavior.
Your WebApp's cannot share the same ClassLoader.
That is a fundamental part of being a Servlet Spec WebApp, the ClassLoader isolation.
Attempting to force it will just create mysterious problems with the ClassLoader hierarchy (InvalidClassChange errors, memory leaks, GC failures, etc)
Perhaps you can detail why you think you need this.
As there's likely already a standard way to accomplish it using the features of the Servlet spec (and not fighting it).

PITest: Configuration isn't applied correctly

I have the following in my pom file:
pom.xml
<reporting>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.1.8</version>
<configuration>
<targetClasses>
<param>com.myService.utility.*</param>
</targetClasses>
<reportsDirectory>/my-service/target</reportsDirectory>
<targetTests>
<param>com.myService.utility.util.*</param>
</targetTests>
<timeoutConstant>5000</timeoutConstant>
<excludeClasses>
<param>com.myService.utility.EmailImpl.java</param>
<param>com.myService.utility.Email.java</param>
<param>com.myService.utility.ValidationUtil.java.java</param>
</excludeClasses>
<avoidCallsTo>
<avoidCallsTo>org.apache.log4j</avoidCallsTo>
<avoidCallsTo>org.slf4j</avoidCallsTo>
<avoidCallsTo>org.apache.commons.logging</avoidCallsTo>
</avoidCallsTo>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
When I run the tests, the timeout doesn't seem to have changed from the default 3000, the classes in excludeClasses are still picked up, and its still complaining about configuration for log4j(althoguh it is log4j2 so this looks like my fault for not specifying). I can't find many examples in the PITest documentation or anywhere else, minus very simple examples using targetClasses and targetTests
EDIT: I tried changing the reporting tags to build tags and removed the reportSets section. There is still no change; the utility src package contains 6 classes, of which the 3 I've outlined in the pom should be excluded, and there are 3 test files in the test counterpart package. the reporter is still pulling in the classes to be excluded and showing as 0% line and mutation coverage. It is also complaining about log4j configs despite the avoidCallsTo values
The configuration needs to be provided under build/plugins, not reporting.
Unfortunately maven doesn't throw any error when it can't map XML to a plugin.
Included/excluded classes accepts globs against java packages - not source files so should look something like :-
<excludeClasses>
<param>com.myService.utility.EmailImpl</param>
<param>com.myService.utility.Email</param>
<param>com.myService.utility.ValidationUtil</param>
</excludeClasses>

How to use Apache Tattletale to analyze duplicate Jar/APIs used in class path

In my project they have used more than 225+ jar files which causing memory issue, while searching on net i come to know Apache Tattletale will analyze and give a report of duplicate classes and JAR/APIs used by the application (Classpath). So i have refereed following links
1) how to use JBoss Tattletale tool
2) Uncover JBoss client jar list with Tattletale
3) Jboss official Documentation
but i didn't get how to execute and run the Tattletale Jar file and my application is not based on maven so i am not using Maven.
I have downloaded tattletale-1.2.0.Beta2.jar file along with jboss-seam-2.3.0.CR1-dist file and used following command
java -Xmx512m -jar tattletale.jar /Java/workspaces/mycoolprojects/projectX output-projectx
but getting following exception
Exception in thread "main" java.lang.NoClassDefFoundError: javassist/NotFoundException
at org.jboss.tattletale.analyzers.Analyzer.getScanner(Analyzer.java:49)
at org.jboss.tattletale.Main.execute(Main.java:608)
at org.jboss.tattletale.Main.main(Main.java:1099)
Caused by: java.lang.ClassNotFoundException: javassist.NotFoundException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
More over i didn't get what is the use of jboss-seam-2.3.0.CR1-dist file. Meaning i can see lot of jar files and lot of code in there but i don't know how does it help to use tattletale.
In the official documentation they have mentioned jboss-tattletale.properties and how can i set/use that.
I was having the same problem and this solution worked for me too.
(downloaded the latest javaassist jar)
Interestingly, tattletale itself suggests that the tattletale jar contains the
javaassist jar
The below steps worked for me:
download jboss-javassist-javassist-rel_3_22_0_cr1-2-g6a9079a.zip from http://jboss-javassist.github.io/javassist/
extract it to a location
go to that location and copy javassist.jar
go to location where your tattletale-1.2.0.Beta2.jar is present
paste javassist.jar here
open command prompt at this path
run command java -jar tattletale-1.2.0.Beta2.jar path_to_application_archive output_path
I inherited an old Maven project configured to use this plugin and got the same javassist errors. The plugin dependencies may be adjusted as shown to make the errors stop.
<plugin>
<groupId>org.jboss.tattletale</groupId>
<artifactId>tattletale-maven</artifactId>
<version>1.2.0.Beta2</version>
<executions>
<execution>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- This is the location which will be scanned for generating tattletale reports -->
<source>${project.build.directory}/${project.artifactId}/WEB-INF/lib</source>
<!-- This is where the reports will be generated -->
<destination>${project.build.directory}/site/tattletale</destination>
</configuration>
<dependencies>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.27.0-GA</version>
</dependency>
</dependencies>
</plugin>

Getting application version from pom

I have a rest endpoint used to return information about application (so far only app version)
But so far this info is hardcoded, and it's pretty easy to forget to change it.
I will be better to retrieve app version from pom or manifest file. Is there any project that brings such functionality?
Spring Boot can refer to the project version defined in pom.xml and expose it via REST using Actuator:
# application.properties
endpoints.info.enabled=true
info.app.version=#project.version#
Then accessing the /info URL (e.g. http://localhost:8080/info) will return:
{"app": {"version": "<major.minor.incremental>"}}
See also: spring boot/spring web app embedded version number
You better use build-in manifest.
new Manifest(Application.class.getResourceAsStream("/META-INF/manifest.mf"))
For the concrete impl-version:
new Manifest(Application.class.getResourceAsStream("/META-INF/manifest.mf"))
.getMainAttributes()
.get(Attributes.Name.IMPLEMENTATION_VERSION)
Using maven do not forget to create the manifest using:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
There is amazing project named Appinfo, please use it and enjoy! (It has an ugly page, I know - but it works :)
AppInfo allows to automatically feed your application with a current version number, build date or build number.
Also excellent Spring Boot Actuator provides feature named Info Endpoint which can publish version information to web or REST.
By default the Actuator adds an /info endpoint to the main server. It contains the commit and timestamp information from git.properties (if that file exists) and also any properties it finds in the environment with prefix "info".
You could use the resource filtering of maven or something like the maven-substitute-plugin.

Categories

Resources