I have several Java projects that pom.xml to define dependencies. It all works nicely but there's a lot of repetition so I am trying to move duplicate dependencies into a new parent pom file.
Let's say my parent pom.xml has the following:
<dependencyManagement>
<dependencies>
<!-- Hazelcast dependencies -->
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>${hazelcast.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
My child pom.xml has:
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
</dependency>
</dependencies>
This isn't too bad as I'm only adding two artifacts. Is there a way to add the two dependencies with only one entry? I tried the following based on an online post, but it doesn't work but it does give an idea of what I was hoping for:
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<artifactId>hazelcast-client</artifactId>
</dependency>
</dependencies>
I'm also depending on several different Jetty artifacts so I'm trying to see if there's a way to reduce content. I know I can write out each artifact dependency separately in the child pom.xml files but I thought I'd see if there's a way to simplify.
Thanks
Related
I am trying to inject the spring-boot-starter-security dependency in a simple spring boot application (Maven). I tried to copy this dependency from the "Securing a Web Application" tutorial from the actual Spring website, I also tried to implement it together with the spring security test dependency and thymeleaf spring security dependency.
So here are the dependencies that get the error "not found":
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
And here it is the full pom file:
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.3.1.RELEASE
com.homehero
homehero
0.0.1
war
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I feel the need to thank y'all in advance and sorry if I'm missing something really stupid, I really hope I'm not!
I solved the problem.
Long story short, a friend of mine suggested doing a new project with Spring Initializer and this time add from the beginning the "Spring Boot Security" dependency. After that, I just needed to compare the pom files. The only difference was that the new project had a:
<scope>test</scope>
line. I added that to my initial project and the first dependency did not get the error anymore. The second dependency was the Thymeleaf spring security one, in order to fix this one I added:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
To my pom file.
So this is how the dependencies look together now:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
That's it, thank you for all the answers you guys also provided.
Take a look in the version of parent POM.xml file. When I've changed the version to 2.0.0 my project founds the dependency.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I had the same problem. follow these steps:
1- Delete the dependencies that are not found.
2- Sync your project.
3- Add the dependencies.
4- sync the project again.
it worked for me hope works for everyone else:)
Not sure how you are creating project.I can tell you simple solution,which is to go to Spring Initializer ,link for which is https://start.spring.io/
There you can add all your required dependencies and then just click on Generate,which will download your project.You can just import the project in your IDE and run maven build.I tried with Spring boot version 2.3.1 only as you mentioned and it worked for me and should work for you.
Also,I would suggest you to user Intellij IDE,which comes with maven support by default,so it will make things easy for you.You can download Intellij free edition from here:
https://www.jetbrains.com/idea/download/#section=windows
Hope it will help you.
I want to supply test dependencies like spring, mockito and junit in every project to make it as easy as possible to write tests.
Should I use dependency management for this dependencies or define them in the parent pom?
Yes , You don't need to define the dependency in every project. Just define the dependency in parent pom. Child project will automatically inherits its parent pom. Also If you want to use different version of Mockito or anything. Just override the parent dependency in child one.
All the common dependencies can be mentioned in the parent pom file. There mainly 4 types of dependencies that can be mentioned in a pom file.
Library Dependencies created by ourselves
Module Dependencies from our own modules
3rd Party library Dependencies
Dependencies for tests
Example
<dependencies>
<!-- Library Dependencies created by ourselves -->
<dependency>
<groupId>it.myapp</groupId>
<artifactId>MyAppBootstrap</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>it.myapp.libs</groupId>
<artifactId>b2b_connecttion</artifactId>
</dependency>
<!-- Module Dependencies from our own modules-->
<dependency>
<groupId>it.myapp.mymodules</groupId>
<artifactId>RevenueManager</artifactId>
<version>${myapp.module.version}</version>
<classifier>classes</classifier>
</dependency>
<!-- 3rd Party Dependency -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<scope>provided</scope>
</dependency>
<!-- Dependencies for tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
there are two ways to achieve it -
you declare the dependencies in the parent pom in the <dependencies /> node, and each child will benefit from the dependency.
Add the dependencies in the parent pom under the <dependencyManagement /> node and in each child that requires it, add the dependency in the node. You can choose not to set the version of the dependency.
So for example, if you declare this in the parent pom:
<dependencies>
<dependency>
<groupId>org.abc</groupId>
<artifactId>xyz</artifactId>
<version>your_version</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.abc</groupId>
<artifactId>xyz</artifactId>
<version>your_version</version>
<scope>your_scope</scope>
</dependency>
</dependencies>
</dependencyManagement>
I am working on a library for some projects which relies on Spark and HBase.
So the POM of the library looks something link this:
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.1.2</version>
</dependency>
...
</dependencies>
And in the specific project that uses the central library (which is published on an internal Maven repository) I have this:
<dependencies>
<dependency>
<groupId>my.group.id</groupId>
<artifactId>myartifact</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
This, however does not then automatically include the dependencies that the library itself has. Therefore I would need to copy the dependency section of the library POM into the application POM.
Do you have any advice what might be missing/wrong?
Thanks and regards!
I'm trying to move from wildfly9 to wildfly 10.
My code works properly on wildfly9
But when I try to deploy my ejb module on wildfly 10 I get the following error:
java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
I tried all the options available out there to correct this error but nothing helped me.
Here are the dependencies that i have in my pom
<dependencies>
<dependency>
<groupId>za.co.ecommunicate</groupId>
<artifactId>pl4sms-billing</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- ehcache dependency -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
<!-- ehcache dependency -->
<dependency>
<groupId>za.co.ecommunicate</groupId>
<artifactId>pl4sms-persistence</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- dependencies require for test asserts -->
<!-- <dependency> <groupId>za.co.ecommunicate</groupId> <artifactId>pl4sms-web</artifactId>
<version>1.0-SNAPSHOT</version> </dependency> -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.13</version>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>tomee-embedded</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
According to the solutions available I have found the the problem is related to hibernate, I have updated hibernate dependencies, changing the scope and also adding dom4j dependency but nothing worked.
The same module gets deployed without any problem on wildfly 9.
Can anybody help me out in resolving this error.
I have found the solution of my question may be it will help others.
i got the solution from this blog.
I added the line in my war's MANIFEST.MF file:
Open {your war}/META-INF/MANIFEST.MF
Add this line at the end - Dependencies: org.dom4j export
and added the following line in persistence.xml:
<property name="hibernate.listeners.envers.autoRegister" value="false"/ >
And it worked for me.
You problem is this:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
It brings in the old dom4j jar: Reference this ticket: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory.
You either need to remove it, declare it as provided in scope, or not run the application on the Wildfly Server (which is probably not your preferred option).
In an eclipse maven project using spring web mvc, I am getting the following error in the Markers tab:
Archive for required library: 'D:/mypath/.m2/repository/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar' in project 'DocumentManager' cannot be read or is not a valid ZIP file
I have checked, and the jar file is in fact present in the url indicated. I even copied a backup of the jar to overwrite the jar file in that location, but that did not get rid of the error either. I forced maven to update, which did not solve the problem. I also restarted eclipse to no effect.
At one point, jta-1.0.1B.jar had been jta-1.0.1B.jar.LatestUpdate, so I shortened the name to jta-1.0.1B.jar
In pom.xml, the location of the error message is line 2, which reads as follows:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
When I download jta-1.0.1B.jar manually from this url, the error in pom.xml goes away but is replaced with new errors in .java class files indicating that 5 methods of the Document class are not valid.
I read this and this, but I am not using struts, I am already including 3.3.2.ga of hibernate, and I do not have a repository tag in pom.xml (which this said did not even solve the problem anyway), so I do not think this is a duplicate.
Can anyone suggest a way to fix this problem? If I need a repository tag, where do I put it? And what else do I change to accommodate its addition?
For anyone who is curious, my pom.xml is included for reference as follows:
<?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>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<description></description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3</version>
</dependency>
<!-- dependency to fix JSPServletException -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.32</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<org.springframework.version>3.2.4.RELEASE</org.springframework.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>DocumentManager</groupId>
<artifactId>DocumentManager</artifactId>
</project>
To fix issues like that, let Maven download the files again:
Delete the folder D:/mypath/.m2/repository/javax/transaction/jta
Run Maven with -U so it tries broken downloads again.
That should try to download the file again and clean up any "residue" in your local repository.
If Eclipse still complains that the JAR file is corrupt:
Refresh your project (F5 or from the context menu)
Clean the project
Try to open the JAR file. Maybe it's really corrupt.
If the JAR file is corrupt, delete the folder again and run Maven once more. Note the URLs which Maven used to download the archive and contact the administrator of that site.
You can manually go to the repository specified in the error console
that is
Archive for required library: '**D:/mypath/.m2/repository/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar**' in project 'DocumentManager' cannot be read or is not a valid ZIP file
Delete the JAR mentioned
Go to eclipse, right click the project and select run as->maven-install.
It will download the right jar file.
You should exclude JTA in your hibernate dependency.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.3.ga</version>
<exclusions>
<exclusion>
<artifactId>javax.transaction</artifactId>
<groupId>jta</groupId>
</exclusion>
</exclusions>
</dependency>
After that, add the jta dependency.
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
The problem with me was fixed by going to Build Path-> Configure Build Path-> Libraries-> Remove the jta lib which has small cross mark on it.
I was able to successfully build my project but was getting this error even after project Refresh/Project Clean.
The maven central repository doesn't contain a jar file for the given groupId/artifactId only a pom.xml.
You are using Spring 3.2 so I suggest you simply upgrade hibernate to the most recent version (4.2.6.Final) which should have a reference to jta 1.1. Or simply include the 1.1 version in your pom which does have a jar in maven central.
To fix this issue simply.
select all libraries in "Maven Dependencies" of related project.
just do "Refresh" of mouse right button...
The reason is cache info, so just refresh the information.
Tried with 1.5.5 Release jar and it worked for me
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.5.RELEASE</version>
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/1.5.5.RELEASE