I am completely new to Maven. I am using eclipse 2021-12 and i am trying to follow the installation from this link but do it in eclipse.
However, i am struggling to carry out the first step in eclipse "Install library into your Maven's local repository by running mvn install". I have created a new simple Maven Project and added the dependency code in step 2. And it gave me an error saying missing jar file.
My question is how do i carry out step 1 in eclipse ?
This is how the pom.xml looks like:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>binance.crypto</groupId>
<artifactId>binance.crypto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.binance.api</groupId>
<artifactId>binance-api-client</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
The error i am getting is missing artifact com.binance.api:binance-api-client:jar:1.0.0:
Solution:
Clone the project from github and import as a normal project (not maven project) in eclipse
Right Click and run as Maven Install
Then it's completed
Related
I've been hitting an annoying issue recently. I have two different maven projects checked out to my development machine. One project depends on the other (let's say Project A depends on Project B), and I actively make changes to both projects. Sometimes though, Project A won't pick up the latest Project B changes. Let's say I make some changes to Project B, I build/install it with...
mvn clean install
I even check my local ~/.m2/repository to see that the jar has been updated. But Project A will still continue to use an older version of Project B. Even though it was just updated... If I remove the entire Project B folder, as in...
rm -rf ~/.m2/repository/project-b/version/
And then build/install Project B again, then at this point my problem is gone. Project A will finally make use of the updated Project B. But I don't want to have to go through this exercise every time. Any clues what could be causing this?
Edit: Here's more or less the relevant parts of the pom.xml for both projects. It's extremely basic.
Project A pom.xml
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>binding-parent</artifactId>
<version>3.0.10</version>
<relativePath/>
</parent>
<groupId>company.group</groupId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>project-A</artifactId>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>company.group</groupId>
<artifactId>project-B</artifactId>
<version>3.1.0-SNAPSHOT</version>
</dependency>
...
</dependencies>
</project>
Project B 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>
<parent>
<groupId>company.group</groupId>
<artifactId>project-B-parent</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>
<groupId>company.group</groupId>
<artifactId>project-B</artifactId>
<version>3.1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
...
<dependencies>
</project>
Since you are using IntelliJ in the right upper corner there is this maven menu, where you can reimport all dependencies which helps me in this case :)
Try below maven command for loading all updated libraries,
mvn clean install -U
Here is my situation:
I'm trying to migrate from Ant to Maven
My project has 3 artifacts: shared api (jar), web app (war), desktop swing app (jar). Latter 2 depends on shared api.
At this moment I'm trying to make web app part work. So I've created 4 poms: eftracker (root pom), eftracker-parent, eftracker-shared, eftracker-web.
If I run mvn package on eftracker all works just perfect -- I have eftracker-shared.jar and eftracker-web.war created as expected
I added tomcat7-maven-pluginto run web app with maven goal tomcat7:run to test changes made during development
I also added eftracker-shared as a project to eftracker-web build path.
My goal:
Now I want to work comfortably in Eclipse, meaning I want to change files, hit Run and in couple seconds be able to test my changes.
During development I will change both: shared and web projects.
My problem:
If I never run mvn install than an attempt to invoke tomcat7:run will lead to error: Failed to execute goal on project eftracker-web: Could not resolve dependencies for project com.skarpushin:eftracker-web:war:1.503.0: Could not find artifact com.skarpushin:eftracker-shared:jar:1.503.0 in central (https://repo.maven.apache.org/maven2)
It appears I have to mvn clean install shared project (or even on root module) each time I change it before I can execute tomcat7:run on web app and see recent changes.
Question is:
Is it possible to make this process automatic?
...OR maybe there is other way how to minimize "maven overhead" during development?
eftracker.pom
<?xml version="1.0"?>
<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.skarpushin</groupId>
<artifactId>eftracker</artifactId>
<version>1.503.0</version>
<packaging>pom</packaging>
<name>eftracker</name>
<modules>
<module>eftracker-parent</module>
<module>eftracker-shared</module>
<module>eftracker-web</module>
</modules>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
</project>
eftracker-parent/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>
<groupId>com.skarpushin</groupId>
<version>1.503.0</version>
<artifactId>eftracker-parent</artifactId>
<packaging>pom</packaging>
<name>eftracker-parent</name>
<!-- ...some common properties, dependencies, build plugins... -->
</project>
eftracker-web/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">
<parent>
<groupId>com.skarpushin</groupId>
<artifactId>eftracker-parent</artifactId>
<version>1.503.0</version>
<relativePath>../eftracker-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eftracker-web</artifactId>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<port>8080</port>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>ROOT##${project.version}</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.skarpushin</groupId>
<artifactId>eftracker-shared</artifactId>
<version>${project.version}</version>
</dependency>
<!-- ...other deps -->
</dependencies>
</project>
Try to use M2Eclipse
https://www.eclipse.org/m2e/
M2Eclipse provides tight integration for Apache Maven into the IDE
with the following features:
Launching Maven builds from within Eclipse
Dependency management for Eclipse build path based on Maven's pom.xml
Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository
Automatic downloading of the required dependencies from the remote Maven repositories
Wizards for creating new Maven projects, pom.xml and to enable Maven support on plain Java project
Quick search for dependencies in Maven remote repositories
So it appears there are 2 things needs to be done:
run mvn compile on parent project in that way all classes will appear in ../parent/target/classes folder. Note that they'll be automatically updated by Eclipse if you change source code
edit Eclipse run configuration and put this checkbox "Resolve Workspace artifacts"
Now I was able to run project as Maven build... with goal tomcat7:run and it worked without the need of parent project to be installed
If I wanted to use just the normal git via the command line and not the one in IntelliJ, what do I need to include in the version control so when I download it, I can get the Maven libraries without manually installing them?
Edit: There is no pom.xml file when the libraries are added to an IntelliJ project, so I was wondering what I need to include so Maven inside IntelliJ can download the libraries.
what do I need to include in the version control so when I download it, I can get the Maven libraries without manually installing them?
The pom.xml file does this:
Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified.
Running mvn install will cause Maven to download your dependencies.
Intellij will automatically understand the changes in the pom files and update libraries of course you should have pom.xml file.
If its a maven based project, you definitely need a pom.xml file like below
<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.test</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>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Once you have a pom.xml file, you can define dependencies like the JUnit dependency defined above with the version you need and maven will automatically take care of downloading the dependency for the project. Once you add any new dependency to the pom.xml, you can run "mvn clean install" from the directory where you have the pom.xml file so that it installs the new dependency.
Hope this helps.
This 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>cassandra</groupId>
<artifactId>connector</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cassandra</name>
<description>cassandra connector</description>
<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.5</version>
</dependency>
</dependencies>
</project>
Error is shown at line 12.
I have copied and pasted the maven dependency from here.
http://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-core/2.1.5
One way to get rid of this error is by downloading bundle file on your local machine from below URL & try below mvn:install command to update it on your local repository.
http://central.maven.org/maven2/com/datastax/cassandra/cassandra-driver-core/2.1.5/cassandra-driver-core-2.1.5.jar
mvn install:install-file -Dfile="cassandra-driver-core-2.1.5.jar" -DgroupId=com.datastax.cassandra -DartifactId=cassandra-driver-core -Dversion=2.1.5 -Dpackaging=jar
Or other way, if you are connecting to Maven repository like Nexus & having rights to update your repository then you can deploy your bundle to Nexus using below mvn:deploy command.
mvn deploy:deploy-file -Durl=http://<>:<>/nexus/content/groups/public -DrepositoryId=nexuspublic -Dfile="cassandra-driver-core-2.1.5.jar" -DgroupId=com.datastax.cassandra -DartifactId=cassandra-driver-core -Dversion=2.1.5 -Dpackaging=jar
In my case I figured out two issues causing this problem, firstly older versions usually throws such errors, so make sure to use the latest version of the dependency. Secondly, using nexus instead of maven repository fixed my issue and it does not say "missing artifact" anymore, I figured this out when I saw a note in https://mvnrepository.com/artifact/pentaho-kettle/kettle-engine/9.3.0.0-115
indicating that the artifact is actually in nexus repository. Lastly, try to be consistent with your versions, for instance, if your using multiple dependencies for the same bundle, stick with the same version as they are most compatible with each other I believe (preferably latest version).
I included a project as dependency in another project. On maven package the included dependency is not compiled as jar, but an empty folder is created.
projects:
main-test (packaging: jar)
main-webservice (packaging: war)
the main-webservice project includes the jar with pom.
main-test pom.xml:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>de.main</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
</project>
main-webservice 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>de.main</groupId>
<artifactId>ws</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>de.main</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build><plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins></build>
</project>
The dependencies of the test project are resolved inside webservice project, so the pom seems to be correct.
Anyhow, if I run "mvn package", the resources of main-webservices compile to target, but the libs folder contains another folder named main-test-1.0.jar. BUT it's a folder, not a packed jar.
What could be wrong here? How can I get the project to be packaged as jar, not as folder?
included dependency is not compiled as jar
Maven never compiles dependencies. It just takes them as they are and either puts them on the classpath or copies them into the WAR. But it never changes the artifact.
That also means the dependency must be in your local repo (somewhere below ~/.m2/repository/) or Maven will be unhappy (= fail with an error).
Note: Maven doesn't have a big memory. It can always only keep a single module in his tiny brain. In Eclipse, you can add another project as it is to the build path but Maven can't do that. For Maven to work properly, you must install all the dependencies in your local repo.
Idea:
Check if the jar exists in your repository
Check if the jar project in eclipse is not referenced in the war project in the Java Build Path
Do it without eclipse mvn plugin:
mvn eclipse:clean (for both projects)
mvn eclipse:eclipse (for both projects)
mvn clean install (for both projects)