i want add org.springframework.spring.web-mvc3.2.0.RELEASE dependency in my project . but when i add this dependency and save that , it show this error :
and 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>fit</groupId>
<artifactId>Example01</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Example01 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>Example01</finalName>
</build>
</project>
It seems that you lost the connection to Maven central half way during the transfer. The problem is that your artifacts could become out of sync with Maven cache. If your local Maven repository is relatively small I would suggest to delete entire repository folder under .m2 and try to rebuild again from the command line (mvn clean install)
Related
I have added slf4j dependency from mvn repository.
My pom.xml is given below after adding that dependency :
<?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">
<groupId>org.example</groupId>
<artifactId>KafkaProject</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
After adding this dependency in my project, it is giving an error saying that:
Dependency 'org.slf4j:slf4j-simple:1.7.25' not found
By the way, I am using IntelliJ IDEA. So, how to resolve this issue ?
It's not giving me the error.
I think the dependencies are not downloaded due to slow network.
Try to update the project by doing Maven Update/Install to download the dependencies again.
Try this 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>org.example</groupId>
<artifactId>KafkaProject</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>simple Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>KafkaProject</finalName>
</build>
</project>
I was learning about "import" scope in maven and did a sample project below,
Project_1 POM file :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
project_2 POM file :
<parent>
<groupId>com.sample</groupId>
<artifactId>project1</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
...
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sample</groupId>
<artifactId>project1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
However, this throws an error stating that the JUnit packages are not available in Project2. When I remove the dependencyManagement tag from project_1 POM file. Everything works fine.
But as per the maven docs,
This scope is only supported on a dependency of type pom in the
section. It indicates the dependency to be
replaced with the effective list of dependencies in the specified
POM's section. Since they are replaced,
dependencies with a scope of import do not actually participate in
limiting the transitivity of a dependency.
I've done as mentioned in the docs, what went wrong here?
It looks like you're trying to use a bill-of-materials (BOM) POM and import that.
Your Project_1 is the BOM POM in this case, and you include all your project's dependencies in the <dependencyManagement> element. It looks like you're doing this correctly.
To import a BOM POM in your project however, you need both <dependencyManagement> and <dependencies>.
For example, your Project_2 pom.xml should include:
<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.sample</groupId>
<artifactId>project1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<!-- Imports the bill-of-materials POM. -->
<dependency>
<groupId>com.sample</groupId>
<artifactId>bom</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Add a dependency from the BOM POM.
Note: no version or scope is required, it's inherited from the BOM POM! -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
Here is the BOM POM definition for the above example:
<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.sample</groupId>
<artifactId>bom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
There is documentation about this on the Apache Maven website (search for "bom").
Update:
BOM POMs and parent POMs are similar but different. BOM POMs are meant purely for importing dependencies into your project. Parent POMs are meant for multi-module projects, and allow you to define Maven coordinates, plugins, and dependencies that will be inherited by all of modules using the parent POM.
Here is an example of using an inherited dependency from a parent POM. Note that there are several elements included here that don't make sense in a BOM POM.
<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>com.sample</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>project1</artifactId>
<packaging>jar</packaging>
<dependencies>
<!-- Inherited from the parent POM. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
Here is the parent POM definition for the above example:
<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.sample</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--Global dependencies...-->
</dependencies>
<build>
<pluginManagement>
<!--Plugins...-->
</pluginManagement>
</build>
</project>
First Make sure you are using Maven version 2.0.9 or later that supports this functionality.
Second your Project1 Pom.Xml is missing the attribute "packaging" Make sure your packaging and type are of the same name so that it inherits all the dependencies.
Also your artifact Id and group ID has to be the same as your project 1's Pom.xml file for it to import the dependency
When in doubt refer to this link
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies
I have Maven project on eclipse, and the project has multiple main entry point within different packages. How can i create .jar correctly so I can choose which main method to run?
I tried creating jar using maven install, but when I run it cannot find or load the main class, and I am running .jar like this.
java jar myproject-0.0.1-SNAPSHOT.jar com.mycompany.project.Main
I also tried this andstill same error
java -cp myproject-0.0.1-SNAPSHOT.jar com.mycompany.project.Main
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>edu.cpp.cs499</groupId>
<artifactId>Netflix-MapReduce</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Netflix-MapReduce</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
</project>
I am currently trying to introduce a BOM (bill of materials) file to my Maven project, but it does not seem to work and I have no clue, why.
This is my bom:
<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.private</groupId>
<artifactId>test.bom</artifactId>
<version>5.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<version.CoreAnnotation>5.0.0-SNAPSHOT</version.CoreAnnotation>
<version.CoreWeb>5.0.0-SNAPSHOT</version.CoreWeb>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreAnnotation</artifactId>
<version> ${version.CoreAnnotation}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreWeb</artifactId>
<version>${version.CoreWeb}</version>
<type>war</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
There are many more, but I excluded them because I think this should be enough as an example.
This is my pom (where I try to include the bom):
<?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>
<artifactId>Core</artifactId>
<groupId>com.private</groupId>
<version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>Core-ear</artifactId>
<packaging>ear</packaging>
<name>Core-ear: EAR Module for private</name>
<properties>
<version.test.bom>5.0.0-SNAPSHOT</version.test.bom>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>test.bom</artifactId>
<version>${version.test.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Whenever I use maven install there should be a collection of all packages defined in the dependencies section appear in the folder \target\Core-ear\
Now the problem: The dependencies defined in the bom don't appear there. What could be the problem?
ps: running mvn install -X for debugging does not seem to help.
This happens because you did not declare the dependencies in your POM. You only declared the <dependencyManagement> section.
In your POM, you need to add the following dependencies, without the version:
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreAnnotation</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreWeb</artifactId>
<type>war</type>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>test.bom</artifactId>
<version>${version.test.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Refer to Introduction to the Dependency Mechanism: BOM are used to factor version of all the artifacts, so you don't need to add it in your <dependency> section.
I'm new to Maven but I'm hooked on what it offers. How do I take a webapp and have Maven package the webapp as a deployable WAR? Additionally, can I set up Maven to automatically version the builds?
Here is an example from the getting started guide:
<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.mycompany.app</groupId>
<artifactId>my-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>my-webapp</finalName>
</build>
</project>
Change to the project's directory and type:
mvn clean package
target/my-webapp.war is built