application.xml updated by maven update project - maven

Good morning all.
Quick question: when I do a "maven update project" my application.xml file is updated.
I have abc-ear/META-INF/application.xml like this :
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
<description>Application abc construite avec le framework Sphinx.</description>
<display-name>def</display-name>
<module id="WebModule_1301067741013">
<web>
<web-uri>def-web.war</web-uri>
<context-root>def</context-root>
</web>
</module>
<module id="WebModule_1306335826653">
<web>
<web-uri>ghi-web.war</web-uri>
<context-root>jkl_bo</context-root>
</web>
</module>
<module id="WebModule_1330011848203">
<web>
<web-uri>mno-web.war</web-uri>
<context-root>mno_bp</context-root>
</web>
</module>
</application>
And my abc-ear/src/dev/application/META-INF/application.xml contains this after "maven update projects" :
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>abc-ear</display-name>
</application>
I'm using maven-ear-plugin :
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<!-- <fileNameMapping>full</fileNameMapping> -->
<!-- <defaultLibBundleDir>.</defaultLibBundleDir> -->
<skinnyWars>true</skinnyWars>
<applicationXml>${basedir}/META-INF/application.xml</applicationXml>
<generateApplicationXml>false</generateApplicationXml>
<archive>
<manifestEntries>
<Date>${maven.build.timestamp}</Date>
<Version>${project.version}</Version>
<!-- <Baseline>${baseline.number}</Baseline> -->
</manifestEntries>
</archive>
<!-- On doit faire en sorte que le numero de version du war soit retiré
sinon, chaque sous version va demander de reconfigurer le serveur -->
<modules>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>abc-web</artifactId>
<contextRoot>/abc</contextRoot> <!-- Voir application XML -->
<bundleFileName>abc-web.war</bundleFileName>
</webModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>def-web</artifactId>
<contextRoot>/ghi_bo</contextRoot> <!-- Voir application XML -->
<bundleFileName>def-web.war</bundleFileName>
</webModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>ghi-web</artifactId>
<contextRoot>/ghi_bp</contextRoot> <!-- Voir application XML -->
<bundleFileName>ghi-web.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
Before mvn clean install, I need to
git checkout application.xml
If i don't do it, it doesn't work.
Can you tell me why ?
maven version : apache-maven-3.0.4
Thank you

Related

JBoss working project with EJB can't get deployed on Tomcat Plume

Structure of project: pom-root, ear project that's dependent on ejb and war. War project also depends on ejb. Everything is created by mvn archetype:generate and managed in IDEA. The overall project gets cleaned and packaged and then the ear is being deployed on TomcatEE Plume 7.0.5.
Task: get user data from servlet and to persist it with JPA + hibernate to PostgreSQL.
Entity class: NewUser
Stateless class: UserEJB
Maven clean and install goes well, but when I start it with Tomcat the following error prevents ear to be deployed:
26-Aug-2018 18:24:37.684 INFO [http-nio-8002-exec-5] org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.createDelegate PersistenceUnit(name=userUnit, provider=org.hibernate.jpa.HibernatePersistenceProvider) - provider time 282ms
26-Aug-2018 18:24:37.684 INFO [http-nio-8002-exec-5] org.apache.openejb.assembler.classic.Assembler.destroyApplication Undeploying app: ...\jpaTomcat\ear\target\ear-1.0-SNAPSHOT
26-Aug-2018 18:24:38.173 SEVERE [http-nio-8002-exec-5] org.apache.openejb.assembler.classic.Assembler.destroyApplication undeployException original cause
java.lang.Exception: deployment not found: RegisterEJB
NewUser class:
package com.jeorgius.entities;
import javax.persistence.*;
import java.io.Serializable;
#Entity
#Table(name = "newuser", schema = "userdata")
#SequenceGenerator(name = "h", sequenceName = "userdata.hibernate_sequence")
public class NewUser implements Serializable {
#Id
#GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "h")
private Integer id;
private String nick;
private String email;
private String pw;
public String getNick() {
return nick;
}
public void setNick(String nick) {
this.nick = nick;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
}
RegisterEJB class:
package com.jeorgius.ejb;
import com.jeorgius.entities.NewUser;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
#Stateless
public class RegisterEJB {
#PersistenceContext(unitName = "userUnit")
EntityManager em;
public void createUser(String nick, String email, String pw) {
NewUser newUser = new NewUser();
newUser.setNick(nick);
newUser.setEmail(email);
newUser.setPw(pw);
em.persist(newUser);
}
}
index.jsp page contains only form to enter nick, email, pw with action to servlet Register:
package com.jeorgius.servlets;
import com.jeorgius.ejb.RegisterEJB;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
#WebServlet("/register")
public class Register extends HttpServlet {
#EJB
RegisterEJB registerEJB = new RegisterEJB();
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String nick = req.getParameter("nick");
String email = req.getParameter("email");
String pw = req.getParameter("pw");
registerEJB.createUser(nick, email, pw);
}
}
persistence.xml on ejb-project:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="userUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.jeorgius.entities.NewUser</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/jeorgius" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="1234" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
ejb-project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<artifactId>jpaTomcat</artifactId>
<groupId>com.jeorgius</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>back</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<name>back</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.3.5.Final</version>
</dependency>
</dependencies>
<build>
<finalName>jpaTomcat</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
war-project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<artifactId>jpaTomcat</artifactId>
<groupId>com.jeorgius</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>front</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>front</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jeorgius</groupId>
<artifactId>back</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
ear-project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<artifactId>jpaTomcat</artifactId>
<groupId>com.jeorgius</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ear</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>
<name>ear</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.jeorgius</groupId>
<artifactId>back</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.jeorgius</groupId>
<artifactId>front</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
</plugins>
</build>
</project>
The exact same project runs well on JBoss server, except for the fact that I use a .xml datasource on JBoss, so persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="userUnit">
<jta-data-source>java:jboss/jeorgiusDS</jta-data-source>
<class>com.jeorgius.entities.Signup</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
I just wanted to test my app on TomcatEE, on which I failed before using JBoss, but I still can't figure out what's wrong. TomcatEE and Tomcat Plume are supposed to work with EJB and JPA.
Tomcat Plume was also used in one of the examples on youtube and it worked well, but the guy who made the video added project libraries manually without Maven. I didn't try to do it myself yet though, but that would leave issue with building it with maven.
I spent a lot of time trying out different stuff. Feel free to ask me questions, if anything is unclear. Thanks in advance!
I think TomEE does not like that <packaging>ejb</packaging>. If you move RegisterEJB to the same project/module where your servlet is then I believe it will work (no ear, just one war file).
If you want to have RegisterEJB in a different artifact I would use <packaging>jar</packaging>.
Also this looks strange:
#EJB
RegisterEJB registerEJB = new RegisterEJB();
It should be:
#EJB
RegisterEJB registerEJB;
#Inject will also work and with that you can change your EJB to something else and it will still work.

Skipping JaCoCo execution due to missing execution data file, in a project with modules and no unit tests

How can i create the jacoco.ext file ?
Which mvn query ?
My projcet has this in the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<reuseForks>true</reuseForks>
<forkCount>1</forkCount>
<argLine>${argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
The project itselfs has no unit tests. But it has 5 modules with unit tests.
Thank you for your help. I use the version 0.8.2 of the jacoco maven plugin.
And i also check a lot of questions here.
I also downloaded an workin example on https://www.mkyong.com/maven/jacoco-java-code-coverage-maven-example/
and it also have the same issue.
Given
a/src/main/java/A.java:
class A {
A() {
System.out.println("Hello from A");
}
}
a/src/test/java/ATest.java:
public class ATest {
#org.junit.Test
public void example() {
new A();
}
}
b/src/main/java/B.java:
class B {
B() {
System.out.println("Hello from B");
}
}
b/src/test/java/BTest.java:
public class BTest {
#org.junit.Test
public void example() {
new B();
}
}
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>a</module>
<module>b</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>prepare-agent</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
a/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>a</artifactId>
</project>
b/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>b</artifactId>
</project>
Execution of mvn clean verify will produce
report in a/target/site/jacoco:
and report in b/target/site/jacoco:

Two classes have the same XML type name maven jaxb plugin , Spring

I have some control over some of my schemas so my question is a little different than the ones similar to this. I have three schemas, c.xsd imports b.xsd, b.xsd imports a.xsd. All three have different namespaces.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="ANamespace" targetNamespace="ANamespace" version="1.0" jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0">
<xs:complexType name="ClassA">
<xs:sequence>
<xs:element name="classAFieldName" type="xs:string" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="BNamespace" targetNamespace="BNamespace" version="1.0" jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0">
<xs:import namespace="ANamespace" schemaLocation="a.xsd"/>
<xs:complexType name="ClassB">
<xs:sequence>
<xs:element name="classBFieldName" type="xs:string" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="CNamespace" targetNamespace="CNamespace" version="1.0" jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0">
<xs:import namespace="BNamespace" schemaLocation="b.xsd"/>
<xs:complexType name="ClassC">
<xs:sequence>
<xs:element name="classCFieldName" type="xs:string" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType>
Class A is generated twice, once in org.testing.common and once in org.testing.c and both of them both have the same namespace #XmlType(name = "ClassA", namespace = "ANamespace". However, Spring doesn't know which one to use. Do I really need ClassA generated twice?
Here is my pom.xml:
<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.wfs.fi.stp</groupId>
<artifactId>testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testing</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<versionRange>[0.13.1,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<configurator>
<id>org.eclipselabs.m2e.jaxb2.connector.Jaxb2JavaProjectConfigurator</id>
</configurator>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>A</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>a.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>a.xjb</include>
</bindingIncludes>
<generatePackage>org.testing.common</generatePackage>
<generateDirectory>${project.build.directory}/common_generated</generateDirectory>
<episode>true</episode>
<episodeFile>${project.build.directory}/common.episode</episodeFile>
<extension>true</extension>
<verbose>true</verbose>
<properties>
<property>
<name>javax.xml.accessExternalSchema</name>
<value>all</value>
</property>
<property>
<name>javax.xml.accessExternalDTD</name>
<value>all</value>
</property>
</properties>
<args>
<arg>-npa</arg>
</args>
<disableXmlSecurity>true</disableXmlSecurity>
<accessExternalSchema>all</accessExternalSchema>
<accessExternalDTD>all</accessExternalDTD>
</configuration>
</execution>
<execution>
<id>B</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>b.xsd</include>
</schemaIncludes>
<generatePackage>org.testing.b</generatePackage>
<generateDirectory>${project.build.directory}/b_generated</generateDirectory>
<bindingIncludes>
<include>b.xjb</include>
</bindingIncludes>
<episode>true</episode>
<args>
<arg>-b</arg>
<arg>${project.build.directory}/common.episode</arg>
<arg>-npa</arg>
</args>
<episodeFile>${project.build.directory}/b.episode</episodeFile>
<extension>true</extension>
<verbose>true</verbose>
<disableXmlSecurity>true</disableXmlSecurity>
<accessExternalSchema>all</accessExternalSchema>
<accessExternalDTD>all</accessExternalDTD>
</configuration>
</execution>
<execution>
<id>C</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>c.xsd</include>
</schemaIncludes>
<generatePackage>org.testing.c</generatePackage>
<generateDirectory>${project.build.directory}/c_generated</generateDirectory>
<bindingIncludes>
<include>c.xjb</include>
</bindingIncludes>
<args>
<arg>-b</arg>
<arg>${project.build.directory}/b.episode</arg>
<arg>-npa</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
<extension>true</extension>
<verbose>true</verbose>
<disableXmlSecurity>true</disableXmlSecurity>
<accessExternalSchema>all</accessExternalSchema>
<accessExternalDTD>all</accessExternalDTD>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run the generation goal once and specify your namespace to package mapping in your binding file instead of in the plugin config:
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<jaxb:bindings schemaLocation="a.xsd">
<jaxb:schemaBindings>
<jaxb:package name="org.testing.common"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="b.xsd">
<jaxb:schemaBindings>
<jaxb:package name="org.testing.b"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="c.xsd">
<jaxb:schemaBindings>
<jaxb:package name="org.testing.c"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>

spring2 annotation has not rendered

I am new to startup a Java with Spring 2.5.5 project. But have some problem that the Spring annotation has not been resolved. I means my JSP shows the spring annotation directly, like this:
${msg}
[ \target\pom.xml ]
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.spring</groupId>
<artifactId>HelloWorldSpringWeb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>HelloWorldSpringWeb Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<jdk.version>1.6</jdk.version>
<spring.version>2.5.6</spring.version>
<jstl.version>1.2</jstl.version>
<servletapi.version>2.5</servletapi.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring MVC framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- for compile only, your container should have this -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servletapi.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>HelloWorldSpringWeb</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/spring2</contextPath>
</webApp>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<wtpContextName>spring2</wtpContextName>
</configuration>
</plugin>
</plugins>
</build>
</project>
[ \WEB-INF\web.xml ]
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
[ \WEB-INF\mvc-dispatcher-servlet.xml ]
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean name="/welcome.htm"
class="com.demo.spring.HelloWorldController" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<context:component-scan base-package="com.demo.spring" />
</beans>
[ com.demo.spring.HelloWorldController.java ]
package com.demo.spring;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
#RequestMapping("/welcome")
public class HelloWorldController {
#RequestMapping(method = RequestMethod.GET)
public ModelAndView helloWorld(){
ModelAndView model = new ModelAndView("index");
model.addObject("msg", "hello world");
return model;
}
}
[ \WEB-INF\pages\index.jsp ]
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<body>
<h2>Hello World!!!</h2>
<h2>${msg}</h2>
</body>
</html>
To access the controller, use this URL:
http://127.0.0.1:8080/HelloWorldSpringWeb/welcome.htm
Finally, output on web browser like this:
Hello World!!!
${msg}
As you see, ${msg} is not rendered. What's wrong?
Thank you very much.
After my investigation, I should correct my question to: "Spring 2.5.6 EL has not been resolved".
And now I know that I can add this statement on every pages those has EL expression inside:
<%# page isELIgnored="false" %>
Yes it can solve my problem. But I don't want to add this statement in too many pages in my project.
I find that it is caused by isELIgnored is default to "true" if web.xml is equal or lower than version 2.3. So that I need to add this code to set isELIgnored to true globally:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
</jsp-property-group>
</jsp-config>
But no luck. The EL is still hasn't been resolved.
Someone can help?
Thanks a lot.

Excluding TestNG Groups From Maven

I have some slow tests that rely on the database that I don't want run every time I build my project with Maven. I've added the excludedGroups element to my pom file as explained http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#excludedGroups but I can't seem to get it working.
I've created a minimal project. Here is the pom.xml:
<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>test</groupId>
<artifactId>exclude</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<excludedGroups>db</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.14</version>
</dependency>
</dependencies>
</project>
And these are the two test classes:
public class NormalTest {
#Test
public void fastTest() {
Assert.assertTrue(true);
}
}
and
public class DatabaseTest {
#Test(groups={"db"})
public void slowTest() {
Assert.assertTrue(false);
}
}
However both tests still run. I can't figure out what I'm doing wrong.
I ended up creating external test suits:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="tests">
<test name="standard">
<groups>
<run>
<exclude name="slow" />
<exclude name="external" />
<exclude name="db" />
</run>
</groups>
<packages>
<package name="com.test.*" />
</packages>
</test>
</suite>
and
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="tests">
<test name="full">
<packages>
<package name="com.test.*" />
</packages>
</test>
</suite>
and specifyied which to run in a profile:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/suites/standard.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
...
<profile>
<id>fulltest</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/suites/full.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
From my experience, the excluded groups feature works only when you have a set of included groups. So in order to do what you want, you need to add all the tests to at least one group (you can do this "easily" by annotating the class rather than methods).
For example (just changing the NormalTest)
#Test( groups = "fast")
public class NormalTest {
#Test
public void slowTest() {
Assert.assertTrue(true);
}
}
and in your configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<groups>fast</groups>
<excludedGroups>db</excludedGroups>
</configuration>
</plugin>
I know that this is not obvious, but it's the way that testng works :S. As a side note, I've always used an external configuration file for testng rather that the embedded configuration in the pom, so the parameter groups might not be correct.

Resources