How to change tomcat version in Tomcat maven plugin? - java

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
By default this plugin gives Tomcat version 7.0.37, how can we point to Tomcat version 7.0.91?
As our security team came up with some vulnerabilities for 7.0.37, we need to upgrade to 7.0.91.
Is there any way we can configure the dependencies for the plugin?

there is a newer version of tomcat7-maven-plugin which uses the tomcat 7.0.47 version. Maybe you want to give it a try.
if you really want to update the version referenced by the plugin you can try to exclude the particular references in the plugin and add dependencies in the dependencies section for the ones you excluded.
<dependencies>
...
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>7.0.91</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
<plugins>
<build>

Additional to the answer from aurelius and for documentation reasons:
It's also documented on the plugin page how to replace given tomcat dependencies with new ones:
https://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/adjust-embedded-tomcat-version.html

Related

Deployment of basic Java web application to AWS : javax/xml/bind/JAXBException

I keep getting this error while trying to deploy an application to AWS:
An internal error occurred during: "Updating AWS Elastic Beanstalk environment:
SampleWebApplication".
javax/xml/bind/JAXBException
Here is what I do:
I create new Maven project based on maven-archetype-webapp 1.0
I configure the pom.xml file with dependencies (full file below)
I type in whatever to index.jsp (it's supposed to be super easy application)
I run it on tomcat7:run, it works like a charm on http://localhost:8080/
I create AWS Server
I select the project, I choose Amazon Web Services Tool --> Deploy to AWS Elastik Beanstalk, choose the added server and I keep getting this message:
I am not able to find any information about this error in the internet. The only thing that I have found is that it is connected to Java version, but I am running Java 1.8 (as was suggested in one post that I found).
Can anyone please help me? I am following this instruction for deployment of the application.
I'm super new to AWS so I don't even know where to start!
index.jsp
<html>
<body>
<h2>Hello There!</h2>
</body>
</html>
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.dominikazb</groupId>
<artifactId>SampleWebApplication</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SampleWebApplication Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<tomcat.version>7.0.50</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<build>
<finalName>SampleWebApplication</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<wtpContextName>todo</wtpContextName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<verbose>true</verbose>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webappDirectory>${project.build.directory}/${project.artifactId}
</webappDirectory>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Project structure
Please, please, please help!
Finally, I find an answer to this problem in the website:
https://github.com/aws/aws-toolkit-eclipse/issues/123
The examples there were in Unix. Mine is in Window 7. What I did base on the website suggestion is:
Find where is the file jaxb-api-2.2.5.jar located. I am not sure if version 2.2.5 is a must. Suggest try whatever you have.
Mine is located in
C:\Users\myUserName\.m2\repository\javax\xml\bind\jaxb-api\2.2.5.
Exit the Eclipse IDE.
Open PowerShell in Admin mode.
cd to your user directory (my case C:\Users\myUserName) and execute the following command to open the Eclipse IDE with a -dev option which points to the jaxb-api-2.2.5.jar.
C:\Users\myUserName\eclipse\jee-2020-09\eclipse\eclipse -dev $(ls ~/.m2/repository/javax/xml/bind/jaxb-api/*/*[0-9].jar | Select-Object -Last 1)
Certainly, the location of your eclipse.exe can be different.
Happy coding!

JAX RS MessageBodyWriter not found for media type=application/json

I am creating Rest client using JAX RS Jersey 2. The client works but only in my IDE (IntellIJ IDEA), when I build it with Maven, using maven-assembly-plugin and run the jar it doesn't work anymore.
I get MessageBodyWriter not found for media type=application/json error.
I have tried adding more dependencies that people suggested in other posts but I don't think a dependency is a problem since it runs in the IDE.
Here is the code that throws the exception
return client.target(uri)
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(transactions.get(0), MediaType.APPLICATION_JSON));
After debugging, when I replace transactions.get(0) with an empty string "", it works.
Here is the pom.xml for maven
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>SequencerControllers</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
Am i missing something? Really bothers me that it runs in the IDE but not when built with Maven since I build it with dependencies.
Check if you have class com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in your resulting JAR. If not, add following dependency:
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.10.0</version>
</dependency>
there's an ordering issue as the Jackson and Jackson / jersey jars don't play well in an "uber" assembly jar. This is because they have same-named files in their individual jars that contain different values.
The assembly plugin will pick one version as the "winner" that gets included in the uber jar. The losing duplicate will not be included and in your case, you are likely getting the wrong copy included in your uber jar.
To fix this, make sure that these 2 entries are moved to the top of the maven dependencies list
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson-version}</version>
</dependency>
I also moved this one at the bottom of the dependencies:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
That combination seemed to fix the uber jar issue in my situation.

How do I add test dependencies to a module in JDK 9 for IntelliJ?

I am building a project with maven 3.3.9 using java 9 (build 9-ea+165). Tests ran and build were successful.
However. IntelliJ Idea 2017.1.2 is complaining and will not compile/run tests with the message 'The module does not have the module 'junit.jupiter.api' in its requirements.
How do I add this for IntelliJ?
Is it necessary?
Screenshot:
Project structure:
From pom:
<dependencies>
<!-- testing -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>9</source>
<target>9</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>4.12.0-M4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
It's possible that your project structure isn't valid anymore. You can try to check if your folder containing your tests is your actual test folder:
Press [Ctrl] [Alt] [Shift] [S] to open Project Structure.
Open "Modules"
Open the "Sources tab"
Your folder containing the tests should be marked as "Tests" (the icon will be green)
There are a few options
First, you may not have imported the project correctly into IntelliJ in the first place. In which case the quickest thing to do is often to simply close the project, remove the intellij files from the source directory (.idea directories and any *.i?l files), and reopen the appropriate root pom file, using the open option (if it gives you the option, choose to create a new project and delete the old project).
Second option is that you have correctly opened the project but you've not reimported it since changing the pom and you don't have autoimport switched on and you ignored the notifications asking you to reload. In which case just open the maven window (usually from a horizontal button on the right of the screen) and hit the reimport button at the top left of the maven window.
The third option is to blow away your caches. This is easily done from the file menu.
There may be others. I'd start from the bottom up.

maven-jaxb1-plugin error while executing in jdk1.6 and maven 3.0.3

I am running a maven script which uses maven-jaxb1-plugin version 1.0.rc-11 to generate the jaxb classes from xsd. The script was running successfully in the java version 1.4 and maven version less than 3 . Now the same script when run in java version 1.6 and maven version 3.0.3 environment throws an exception **
A required class was missing while executing
org.jvnet.jaxb1.maven2:maven-jaxb1-plugin:1.0.rc-11:generate:com.sun.msv.grammar.Grammar
**
All the dependencies for this plugin are available in my repository.Still I am getting this error.
Below is my pom.xml
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>javax.xml.parsers</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb1.maven2</groupId>
<artifactId>maven-jaxb1-plugin</artifactId>
<version>1.0.rc-11</version>
<executions>
<execution>
<configuration>
<schemaIncludes>
<include>response.xsd</include>
</schemaIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Is it like maven-jaxb1-plugin can not be used in jdk1.6 and maven 3.0.3 environment.Any help is much appreciated,Thanks.
The class that it says it is missing, com.sun.msv.grammar.Grammar, is present in jaxb1-impl.jar according to findjar.com:
http://www.findjar.com/class/com/sun/msv/grammar/Grammar.html
That class does not seem to be present in jaxb-impl.jar:
http://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl/1.0.6
It does seem to be present in jaxb1-impl.jar:
http://mvnrepository.com/artifact/com.sun.xml.bind/jaxb1-impl/2.0
So maybe change your dependency to:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb1-impl</artifactId>
<version>2.0</version>
</dependency>

Why I can't use Spring and Blossom annotations?

I use Magnolia CMS and Blossom.
When I add annotations to my classes I get something like this:
annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations)
#Template(value="Blossom Template")*
Spring annotation(like #Controller) doesn't compile too.
Where is my mistake?
My pom.xml dependencies:
<dependencies>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-blossom</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-module-admininterface</artifactId>
<version>4.3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-taglib-cms</artifactId>
<version>4.3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-taglib-utility</artifactId>
<version>4.3.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
You have to change your maven.compiler properties to compile with java 1.5.
<properties>
<!-- maven-compiler-plugin configuration -->
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
Another way to do this (but less discreet) is this :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Resources :
http://maven.apache.org/ - compile MoJo - Source
On the same topic :
How can I force maven to package my project against 1.5?
I am happy this got answered but encourage you to use the Magnolia community, especially the mailing-list to ask questions about Magnolia in the future. This will benefit you and the community.
See http://www.magnolia-cms.com/home/community/mailing-lists.html
Thanks
- Boris

Categories