I'm trying to build a Maven project from work, which has servlet-api 3.1.0 as a provided dependency:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
But then fails to compile because it cannot find getRequestURL() from javax.servlet.http.HttpServletRequest.
Later, I found out it's using an older version of servlet-api which I never included in my POM:
Downloading from central: https://repo.maven.apache.org/maven2/javax/servlet/servlet-api/2.2/servlet-api-2.2.jar
Downloaded from central: https://repo.maven.apache.org/maven2/javax/servlet/servlet-api/2.2/servlet-api-2.2.jar (41 kB at 63 kB/s)
Maybe that version of servlet-api is comming from a dependency, but I don't know from which one, they are a lot.
How can I override that version with the one I added in the project's POM?
You can try couple of things.
Try mvn dependency:tree to see if it is getting downloaded as part of another dependency.
If you don’t see the dependency getting downloaded as part of another dependency, clean you local repository( it might be inside .m2 directory) and do a clean install of your application.
you can also share your pom.xml so that others can take a look and help.
Related
I am upgrading to wildfly 21.0.2.Final for an application and wanted to pull the BOM for it rather than linking the dependencies that I needed 1 at a time.
mvnrepository says it should look like this:
<!-- https://mvnrepository.com/artifact/org.wildfly/wildfly-feature-pack -->
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-feature-pack</artifactId>
<version>21.0.2.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
However, when I attempt to package that using mvn clean package i get these errors:
Could not resolve dependencies for project org.example:test:war:1.0-SNAPSHOT: The following artifacts could not be resolved: org.apache.taglibs:taglibs-standard-spec:jar:1.2.6-RC1, org.apache.taglibs:taglibs-standard-impl:jar:1.2.6-RC1, org.apache.taglibs:taglibs-standard-compat:jar:1.2.6-RC1: Could not find artifact org.apache.taglibs:taglibs-standard-spec:jar:1.2.6-RC1 in central (https://companyNameglobal.jfrog.io/companyNameglobal/maven-all)
It appears as if the artifacts don't exist, but then why would they be required in the wildfly BOM?
Any help would be great.
When I add the below dependency in my pom.xml:
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.107.0</version>
</dependency>
compiled dependencies like com.google.api.grpc » proto-google-cloud-pubsub-v1 should be downloaded in 1.89.0 (refer https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub/1.107.0).
But in my repository, when I am adding this dependency those compiled dependencies are downloaded with lower versions e.g: com.google.api.grpc » proto-google-cloud-pubsub-v1 downloaded in 1.41.0.
Why this is happening? And what should be done to overcome this?
They are probably grabbed from some other time of your dependency tree.
You can check that with mvn dependency:tree.
To fix a transitive version, put an entry into <dependencyManagement>.
I have a small maven web project. Its pom includes dependencies to other libraries. One of them has a dependency to slf4j-api.
When running maven's clean install from inside IntelliJ IDEA the resulting war file includes slf4j-api.jar in WEB-INF/lib
Now we have configured a TeamCity maven build for the project. It builds without any errors, but it doesn't include this specific transitive dependency (whereas it includes others).
Do you have any general hints to why this might happen?
Currently we added the dependency directly to the main pom even though we don't need it there...
In the main pom
<dependency>
<groupId>xxxxxxxxx</groupId>
<artifactId>mylibrary</artifactId>
<version>1.0.20</version>
</dependency>
in mylibrary's pom
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
I haven't specified any scope, so I suppose it's compile in any case.
Sorry for the spelling, I'm french
I try to install with scope a jar for oracle in my project
Here my pom.xml
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
<scope>system</scope>
<systemPath>C:/Users/bin/Desktop/dossier_access/instantclient_12_1/ojdbc7.jar</systemPath>
</dependency>
The maven compile didn't function
I did after (it works)
mvn -X install:install-file -Dfile=C:/Users/bin/Desktop/dossier_access/instantclient_12_1/ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar -DpomFile=C:/Users/Documents/Projets/version7/integration-archetype/batch/packaging/integration-archetype-batch/pom.xml
but mvn install gives :
[WARNING] The POM for oracle.jdbc:ojdbc7:jar:12.1.0.2 is missing, no dependency information available
[WARNING] The POM for oracle.jdbc:ucp:jar:12.1.0.2 is missing, no dependency information available
BUILD FAILURE
Thank you for your responses,
i'm beginner with Maven and I have already see on the other posts...
What i usually do is first install jdbc driver in local repository so it is available for all apps in local machine.
Then just use regular dependency tag to include it in you pom file.
Look at this quick tutorial:
http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/
After installing a 3rd party into your local repo (that is what you did with mvn install:install-file) you can reference it the following way:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
And no path information is required anymore.
I am doing a project that has dependencies on some classes from the mahout and hadoop core jars. I was using javac with the classpath option to include them before, but someone suggested to me that I should use maven to build my project instead. However, I am not sure how to add the dependencies to these jar files which are located in my /usr/local directory.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.205.0</version> <!-- or whatever version -->
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
Add this to your pom:
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>some.group</groupId>
<artifactId>hadoop</artifactId>
<version>some.version</version>
</dependency>
</dependencies>
If you have a copy of the jar to be used for say the hadoop example above, execute this command:
mvn install:install-file -Dfile=/some/path/my-hadoop.jar -DgroupId=some.group -DartifactId=hadoop -Dversion=some.version -Dpackaging=jar
Have a look at the maven documentation, especially the part on dependency management. If you want to use Maven you should get to know the basics (one of which is dependency management).
Basially you define your project's dependencies in the <dependencies> section of your pom. Look up maven central (the most common online repository) for the dependencies you want or search for other online repositories that might contain them.
If you can't find them, add the dependencies you want anyways (think of a sensible group id, artifact id and version) and try to compile. Maven will complain about the dependencies missing and provide a basic command to put those dependencies into the local repository. Copy those commands and fill in the appropriate path to the jar file and maven will deploy that dependency in your local repository.
Note that you should first look for the dependencies in an online repository since otherwise you'd have to manually deploy each new version in your local repo.