I want to move properties like version and other properties to pom.properties file.
I have already tried with properties-maven-plugin but still not getting any success.Please let me know how can i achieve this.
<build>
<plugins>
<!-- Maven clean plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>pom.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>....
Here is my pom.properties file data..
appserver.home=D:\apache-tomcat-7.0.64
central=http://192.168.0.110:9999/repository/internal/
snapshot=http://192.168.0.110:9999/repository/stablesnapshots/
spring.version=4.0.5.RELEASE
hibernate.version=4.3.5.Final
log4j.version=1.2.17
jdk.version=1.7
context.path=Evoke
cxf.rt.frontend.jaxrs.version=3.0.0
cxf.bundle.version=2.7.10
cxf.bundle.minimal.version=2.7.10
javax.ws.rs.api.version=2.0-m10
commons.httpclient.version=3.1
jackson.version=2.0.1
jersey.multipart.version=1.18
spring.security.version=3.2.7.RELEASE
drools.version=6.2.0.Final
itext.version=4.2.0
quartz.version=2.2.1
Have you tried this?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
<goal>write-project-properties</goal>
</goals>
<configuration>
<files>
<file>pom.properties</file>
</files>
<outputFile>out.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
It should do the trick. Goals are executed in the order they are declared.
Update based on comments
The problem with having an external file to hold the versions of your dependencies is that when you install or deploy your artifact, the POM will look like this in repository, if it was possible:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
When someone else tries to depend on this POM, how does he or she know what ${spring.version} resolves to? The answer is in the external file, which is embedded - if we are lucky - in the artifact (jar file). And to find the artifact in the repository, you need to know ${spring.version} so it becomes a catch-22 problem.
Now, having said this, Maven has its own mechanism for doing this:
<dependencyManagement> and <properties>:
DependencyManagement
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<!-- No need to specify version, it is inferred from the section above -->
</dependency>
</dependencies>
Properties
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring.version can be reused, because Maven properties behave like constants -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
The good thing is, if you you declare your versions in the <dependencyManagement> section, you can create a POM with only these type of entries in it, and have other POMs import the versions from that POM. This webpage describes how it works: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies
Since POMs always should be version controlled, you get all the added benefits from it: traceability, dependency control, portable builds, etc.
Related
My supervisor asked me to convert an old Maven project we have lying around into a Spring Boot project such that we are able to access the project's backend via RESTful interaction (before that the project's backend was only accessible via a console interface).
So, first I added a simple Spring Boot application in a separate package of project. After that I began to extend the pom.xml of the project by the dependencies needed for Spring Boot and adjusted the overall project setup. Now, I tried to run the backend of the old project, which turned out to be working. However, the simple Spring Boot application did not.
I narrowed down the problem to a conflicting dependency in the "old" part of the pom.xml:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.1</version>
</dependency>
When I leave this dependency in the pom.xml the old backend works, but the Spring Boot application fails with the following error:
WARN: Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
If I comment this dependency out the Spring Application works completely fine, but the old backend fails. I use the version 2.0.4.RELEASE of spring-boot-admin-starter-server. I think that the old backend's version of the logging package is different from the one included in spring-boot-admin-starter-server. However, I somehow need both versions in my project.
What's not possible:
Updating the old sources, since some of them have a coyright of an
external company
What I already tried, but I wasn't successful with:
Exclude the logging from then Spring Boot depedencies. This results in the following error:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
I also to tried to work with the shade plugin as some suggested from my web research. Unfortunately, I was not able to solve the problem with this approach.
Does anyone have suggestions how to solve this problem? I would be very grateful. I am not used to solve dependency problems of this kind. Please excuse me, if I am missing something obvious.
-lema
EDIT pom.xml (unfortunately I had to leave out bigger parts of it) :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<packaging>jar</packaging>
<description></description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.0.2</spring-boot-admin.version>
<spring-boot-dependencies.version>2.0.4.RELEASE</spring-boot-dependencies.version>
...
<rat.skip>true</rat.skip>
<log4j-version>2.6.1</log4j-version>
</properties>
<repositories>
...
</repositories>
<dependencyManagement>
<dependencies>
<!-- Necessary dependency for running Spring Boot without starter parent -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
...
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
<!-- TODO The version of this dependency lets Spring Boot fail, but is
necessary tu run the old backend -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-iostreams</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
...
</dependencies>
<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
...
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>prepare-config-zip</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/assembly/config.xml</descriptor>
</descriptors>
<finalName>configs</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>prepare-dist-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/dist.xml</descriptor>
<finalName>...</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<requireJavaVersion>
<version>1.8</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>attach-standalone</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>standalone</shadedClassifierName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dont-attach-standalone</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<!-- Prevent huge shaded artifacts from being deployed to Artifactory -->
<outputFile>...</outputFile>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
EDIT: I just found out that if you remove the version element inside of the conflicting dependency the Spring Boot Application works, but unfortunately the backend then fails.
So I found a solution, but that's probably not the best way to do it:
I just replaced the <spring-boot-dependencies.version>2.0.4</spring-boot-dependencies.version> with an older version that is compatible with the conflicting logging dependency, namely version 1.4.7.RELEASE.
This is the latest version at which both the Spring Boot application and the backend are working simultaneously (found that out by try-and-error).
Anyway, thank you very much for your help.
Cheers
I really do not know what is wrong with my Spring configuration. Could you give me hand?
My code (simplified version):
App.java:
public class App {
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
ctx.close();
}
}
Config.java:
#Configuration
#ComponentScan
public class Config {
#Bean
public JdbcOperations jdbcTemplate(DataSource ds) {
return new JdbcTemplate(ds);
}
}
pom file:
<properties>
<!-- Generic properties -->
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Spring -->
<spring-framework.version>4.2.5.RELEASE</spring-framework.version>
<!-- Hibernate / JPA -->
<hibernate.version>4.2.1.Final</hibernate.version>
<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
<!-- Test -->
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Test Artifacts -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.185</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
My folder structure:
After I maven package it, when I run the jar I got:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/annotation/AnnotationConfigApplicationContext
at App.main(App.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.annotation.AnnotationConfigApplicationContext
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)
in which, the line 10 is the AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
In addition:
I am writing the code when I was wathcing a spring tutorial:Spring Framework Tutorial 4: Database programming with JdbcTemplate
And his source code is at:github
The only difference with the source code is that I added the MainClass in the pom file.
Thank you so much!
Sincerely
The reason for this is, inside your jar you have only your classes without any dependencies. To include all the dependencies inside your jar you need to create a fat jar.
Replace your build block with following inside pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
After running mvn clean package you will get two jar inside your target directory, first one is without dependency and the second one is with dependencies. Run the second jar.
CustomerJdbc-0.0.1-SNAPSHOT.jar
CustomerJdbc-0.0.1-SNAPSHOT-jar-with-dependencies.jar
The reason that you're getting that is because the maven-jar-plugin doesn't actually include any of the JARs that are referenced in the POM file by default.
There are a few ways that you can sort this out, this answer seems pretty comprehensive.
Also note that when referencing the main class in the POM, you need to reference it with the fully qualified class name (net.ubilife.spring.customerjdbc.App).
You can also run it with Shade to build the jar with the dependencies.
Just add "shade:shade" to the goals.
Example:
mvn clean install shade:shade
As everyone knows jsp can't work with classes outside current osgi web archive bundle. This is a bug in GF. The developers of glassfish for workaround of this bug https://java.net/jira/browse/GLASSFISH-11208 offer to use offline jsp compiler (by other words to compile jsp files not during deployment time but during archive building time). Ok, and I used jspc-maven-plugin to compile my jsp during wab building.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<id>compile</id>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
The jsp are compiled and I see their .classes in built web archive.
Now the problem - how can I make glassfish use my compiled jsp but not to compile it itself? Because I see that GF ignores compiled .classes and generate .javas and compile them itself.
EDIT 1 What I make up to now:
1) I added to glassfish-web.xml
<jsp-config>
<property name="usePrecompiled" value="true"/>
<!-- to see it doesn't generate .javas -->
<property name="keepgenerated" value="true" />
</jsp-config>
2)And when I build my wab archive I have jsp classes in WEB-INF/classes/jsp/... However, I get exception that jsp file not found. When I manually move jsp classes to WEB-INF/classes/org/apache/jsp... I see that container now sees these classes but I get
StandardWrapperValve[default]: Servlet.service() for servlet default threw exception
java.lang.NoClassDefFoundError: org/apache/jsp/... (wrong name: jsp/...)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1925)
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:978)
at org.glassfish.osgijavaeebase.BundleClassLoader.loadClass(BundleClassLoader.java:79)
at org.glassfish.osgiweb.OSGiWebDeploymentContext$WABClassLoader.loadClass(OSGiWebDeploymentContext.java:169)
at org.glassfish.osgiweb.OSGiWebDeploymentContext$WABClassLoader.loadClass(OSGiWebDeploymentContext.java:154)
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:654)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:202)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)
So know this is the right path - org/apache/jsp. The question is how to make maven plugin to output to this direction?
EDIT 2
So I found the settings of this maven plugin -
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<id>compile</id>
<configuration>
<packageName>org.apache.jsp</packageName>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
However, this is the final point but not result. As I get no exception, bute the returned http request is empty (blank page in browser). Seems I should use another maven plugin but which one?
So, to all steps which I did and explained in my edit it is necessary to modify web.xml file because plugin will add there mapping for servlets generated from jsp pages. So, the final settings are :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<id>compile</id>
<configuration>
<!-- package where the compiled jsp classes will be put -->
<packageName>org.apache.jsp</packageName>
<!-- the plugin adds servlets to this web.xml file -->
<outputWebXml>${project.build.directory}/web.xml</outputWebXml>
<verbose>true</verbose>
<target>8</target>
<source>8</source>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
EDIT
Finally I found out that the version of jasper in GlassFish 4.1 is not known or even can be modified -> I got exceptions that such method not found etc. So I ended with the following - I donwloaded the sources of this plugin and made it use the version of the jasper in glassfish. I did not do any modifications in source code of the plugin, only in pom.xml. So the final pom became:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--<parent>
<artifactId>mojo</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>11</version>
</parent>-->
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>1.4.6</version>
<packaging>maven-plugin</packaging>
<name>Maven Jspc plugin</name>
<developers>
<developer>
<name>Jeff Genender</name>
<email>jgenender#apache.org</email>
<organization>Savoir Technologies</organization>
<organizationUrl>http://www.savoirtech.com</organizationUrl>
<timezone>-7</timezone>
</developer>
</developers>
<contributors>
<contributor>
<name>Grzegorz Slowikowski</name>
<email>gs#tiger.com.pl</email>
<organization>Scott Tiger S.A.</organization>
<organizationUrl>http://www.tiger.com.pl</organizationUrl>
<timezone>+1</timezone>
</contributor>
<contributor>
<name>Pawel Pastula</name>
<email>pablo#tiger.com.pl</email>
<organization>Scott Tiger S.A.</organization>
<organizationUrl>http://www.tiger.com.pl</organizationUrl>
<timezone>+1</timezone>
</contributor>
</contributors>
<dependencies>
<!-- from glassfish 4.1.1 modules folder we need:
javax.servlet.jsp.jar
javax.servlet-api.jar
javax.servlet.jsp-api.jar
javax.el.jar
javax.servlet.jsp.jstl-api.jar
javax.servlet.jsp.jstl.jar
what versions of this jar you can find out in parent pom of glassfish
http://repo.maven.apache.org/maven2/org/glassfish/main/glassfish-parent/4.1.1/glassfish-parent-4.1.1.pom
and in manifest file
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.2-b01</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp</artifactId>
<version>2.3.3-b02</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.4</version>
</dependency>
<!-- we need this dependency as it contais tld files for core tag library -->
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>org.apache.jasper.glassfish</artifactId>
<version>2.2.2.v201112011158</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
When you will compile you bundle you will have to add the following dependencies:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp</artifactId>
<version>2.3.3-b02</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.4</version>
</dependency>
Besides you will need to import some packages from glassfish to make it work. So in result you can use precompiled jps files with glassfish, but you need to make some things before it. And as you see you link your code to GF.
The most important thing - you can work with classes from other osgi bundles in jsp! For those who work with osgi in java-ee this can be very important. After doing all these steps I must conclude that GF IS NOT SUPPORTED TO BE USED WITH PRECOMPILED JPS FILES in spite of suggestions from the developers.
I hope at least one will appreciate all the solution, because it seems to me this is the first description in internet how to use precompiled jps pages with GF. By the way if you use osgi and it complains it can't find classes import the necessary packages.
I tried to integrate PMD in one of my project (I am using MAVEN Build tool)
When I try to integrate, I can see XML configuration files are mandatory.
I have tried to download PMD plugin - I expected global ruleset files might be available in PMD plug in, but they are not.
I used below link:
https://sourceforge.net/projects/pmd/?source=typ_redirect
After googling, I have seen one link to get ruleset
http://grepcode.com/file/repo1.maven.org/maven2/pmd/pmd/4.3
I cant download all XML files.
Is there any way to download/update through build or can we get all XML files in one location anywhere? I tried my level best to search in google and couldn't figure it out.
I attached pom.xml here. Can you please let me know how to add my ruleset automatically whenever PMD updated automatically?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.scm</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>SCM-PRODUCT</name>
<description>SCM Product for learning purpose</description>
<properties>
<java.version>1.7</java.version>
<hibernate.validator.version>5.2.4.Final</hibernate.validator.version>
<javax.el-api.version>2.2.4</javax.el-api.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checkstyle-config-url>
D:/rules/checkstyle/2.0/checkstyle-2.0.xml
</checkstyle-config-url>
<checkstyle.version>6.18</checkstyle.version>
<log4j.version>1.2.17</log4j.version>
<!-- TEST CASES RELATED BEGINS-->
<junit.version>4.12</junit.version>
<!-- TEST CASES RELATED ENDS HERE-->
<!-- STATIC CODE ANALYSIS PROPERTIES -->
<findbugs.plugin.version>3.0.3</findbugs.plugin.version> <!-- Reports on common code mistakes and pitfalls -->
<checkstyle.plugin.version>5.0</checkstyle.plugin.version> <!-- Checks Code Style for Developers -->
<pmd.plugin.version>3.6</pmd.plugin.version> <!-- Source Code Analyzer -->
<doxia.module.markdown.version>1.3</doxia.module.markdown.version>
<javadoc.plugin>2.8.1</javadoc.plugin> <!-- Generates JavaDoc -->
<jxr.plugin>2.3</jxr.plugin> <!-- Cross reference report of project source code -->
<!-- REPORTING TOOL PROPERTIES -->
<project.info.reports.plugin>2.4</project.info.reports.plugin> <!-- A plethora of miscellaneous report: info, ci, dependencies, scm, plugins, etc. -->
<site.plugin>3.1</site.plugin>
<sonar.plugin>3.2-RC3</sonar.plugin> <!-- Analysis and metrics on code over time -->
<surefire.plugin>2.12</surefire.plugin> <!-- Reports Test Results -->
<taglist.plugin>2.4</taglist.plugin> <!-- Reports on Tags such as #todo and //TODO -->
<versions.plugin>1.3.1</versions.plugin>
<maven-compiler-plugin>3.1</maven-compiler-plugin>
<cobertura.plugin>2.5.1</cobertura.plugin> <!-- Reports Test Coverage -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<modules>
<module>services</module>
<module>presentation</module>
<module>service_validator</module>
<module>jsonvo</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>${javax.el-api.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- http://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/net.sourceforge.pmd/pmd -->
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>5.4.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugin</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<includeTests>true</includeTests>
<rulesets>
<ruleset>${checkstyle-config-url}</ruleset>
</rulesets>
<minimumTokens>100</minimumTokens>
<targetJdk>${java.version}</targetJdk>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.plugin.version}</version>
<configuration>
<targetJdk>${java.version}</targetJdk>
<minimumTokens>20</minimumTokens>
<skipEmptyReport>false</skipEmptyReport>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<!--<includeTests>true</includeTests>-->
<rulesets>
<ruleset>${pom.basedir}/pmd-rulesets.xml</ruleset>
</rulesets>
<!--
<excludeRoots>
<excludeRoot>target/generated-sources/antlr</excludeRoot>
<excludeRoot>target/generated-sources/antlr/com/puppycrawl/tools/checkstyle/grammars/javadoc</excludeRoot>
</excludeRoots>
-->
</configuration>
<executions>
<execution>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
<goal>cpd-check</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs.plugin.version}</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<excludeFilterFile>config/findbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
</plugins>
</build>
</project>
If you don't need to use your custom pmd rulesets you can omit the rulesets tag altogether.
If you want to use only some of pmd rulesets you can use predefined ones:
<rulesets>
<ruleset>/rulesets/java/braces.xml</ruleset>
<ruleset>/rulesets/java/naming.xml</ruleset>
</rulesets>
You are using version 3.6 of the maven-pmd-plugin. There is a default value for the rulesets - it's java-basic, java-imports and java-unusedcode. See the maven-pmd-plugin documentation.
If you want to start with these rulesets, you can omit the rulesets tag altogether, as krzyk mentioned.
Maven Plugin 3.6 uses PMD 5.3.5 - so downloading rulesets for PMD 4.3 will not work.
But, you don't need to download the rulesets. You can create your own custom ruleset, which references the rules you want to have checked in your code. And this would be your file pmd-rulesets.xml.
Is there any way to download/update through build or can we get all XML
files in one location anywhere?
There is no such a ruleset. Enabling all rules PMD provides, doesn't make sense, as some rules contradict each other. Please read "Best Practices": Choose the rules that are right for you.
Can you please let me know how to add my ruleset automatically whenever PMD
updated automatically?
You don't need to add your ruleset - you are using it already. However, if a new PMD version has new rules, you won't necessarily have these new rules activated. So, you might want to read the release notes of PMD and checkout if there are new interesting rules. Then you can reference the new rules in your ruleset file.
For the java language, you can see the available rules in the Rulesets index.
in my pom.xml I've configured maven-jaxb-plugin but I'm getting a "A required plugin was not found: Plugin could not be found - check that the goal name is correct: Unable to download the artifact from any repository" because of it. My config is like this:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generate-package>tld.mycompany.myproject.data.ws-schema</generate-package>
<schemaDirectory>src/main/resources/ws/xsd</schemaDirectory>
</configuration>
</plugin>
In dependencies, I have added the following.
<dependency>
<groupId>maven-plugins</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.5</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2</version>
</dependency>
What am I missing? Why can't it find the correct artifacts?
Cheers
Nik
I suggest you use, when facing such a problem, one of the available maven search engines :
mvnbrowser
jarvana
mvnrepository
the two first having my preference. Here is what they say about your artifacts :
maven-jaxb-plugin is available at Apache
maven-jaxb2-plugin 0.7.5 is not known. The most up-to-date version, is 0.7.3 on mvnbrowser and 0.7.4 on jarvana. which may be the reason why your maven build is broken
jaxb-api 2.2 is available at both JavaNet and JBoss repositories
Well, wion't do all the job for you, as I guess you get the picture now.
You can find version 0.7.3 on the Java.net maven repository:
http://download.java.net/maven/2/