Another way to ask this question is:
How to authenticate maven project with Azure personal access token so that Maven build can download artifacts published on Azure Artifacts
I have Personal access token, to authenticate. But the problem is what would be the pom.xml which help maven project to authenticate.
Or more simple words
How to configure the maven project to download artifacts from maven central repo and some private artifact publisher also. In my case private artifact publisher is Azure Artifacts.
Fist of all set your Azure Personal Access Token in system environment variable.
like environment variable name key is AZURE_PAT then access this in settings.xml
You just need to add a settings.xml under C:\Users\<UserName>\.m2
settings.xml will be like
<settings>
<servers>
<server>
<id>AzureRepo</id>
<username>AZURE_ARTIFACTS</username>
<password>${env.AZURE_PAT}</password>
</server>
</servers>
</settings>
Then Open pom.xml and add the following repository attribute under repositories attribute. Your azure artifactory URL will be provided by Azure artifactory.
<repository>
<id>AzureRepo</id>
<url>Artifactory URL provided by Azure</url>
</repository>
So your pom.xml will look like this. BTW this pom.xml have spring dependencies.
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.basic</groupId>
<artifactId>basic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>basic</name>
<description>basic maven project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</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>
</dependencies>
<repositories>
<repository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
</repository>
<repository>
<id>AzureRepo</id>
<url>Artifactory URL provided by Azure</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This can help you to download azure artifact in maven repository.
Related
I'm following a Udemy Course on learning SpringBoot, but I can't seem to get one of the dependencies installed. The tutorial asks to import a Tomcat dependency into pom.xml (in order to utilize JSP pages from resources), but after trying to import it:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId> <!-- Error comes from here -->
<scope>provided</scope>
</dependency>
I get the following error on the commented line.
Dependency 'org.apache.tomcat.embed:tomcat-embed-jasper:10.0.21' not found
What am I missing? I'm using IntelliJ, Java 18.0.1.1, and here is my 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springboot</groupId>
<artifactId>springboot-first-web-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-first-web-app</name>
<description>My first SpringBoot web application from the Udemy Course</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
I will edit this to provide any additional information needed
Can you remove the <repositories> section in pom.xml and try to build. Looks like the jar is not available in Spring repository. It will get downloaded from maven central if none mentioned.
I'm brand new to Java. I'm following https://spring.io/guides/gs/rest-service/#scratch (mostly). I'm at the point of standing up the web service, but I'm getting the error in the title.
I'm running
./mvnw clean package
My pom.xml is
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<groupId>caleo</groupId>
<artifactId>greeter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>greeter</name>
<description>Greeter Application</description>
<repositories>
<repository>
<id>spring-releases</id>
<url>http://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>http://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Questions that have not helped:
Missing artifact org.springframework.boot:spring-boot-starter-parent:jar:1.3.2.RELEASE
The recommendation is to use a parent tag, but I have
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
In my pom.xml and that doesn't solve the issue. I tried adding the dependecyManagement tag, but got the error
package org.springframework.boot does not exist
Maven and Spring Boot - non resolvable parent pom - repo.spring.io (Unknown host)
This is different from my error message. Also, the recommended solution is to check if you can access http://repo.spring.io/, which I can.
Spring boot , pom.xml
This is another network issue. I should have a direct network connection.
(Basically all the quetions I found the answer is parent, dependencies, or network issues, all of which I can rule out.)
I've been reading around on this site and others, trying to figure out how add these external jars without doing mvn install, and haven't had any success. I was reading somewhere that maven-shade could address my problem, but I could never get that to work? I know spring boot doesn't like system scope but it seems to error out if I choose something else?
<?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>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<dependency>
<groupId>sample</groupId>
<artifactId>com.sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/enterprise.jar</systemPath>
</dependency>
<dependency>
<groupId>sample1</groupId>
<artifactId>com.sample1</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/gs.jar</systemPath>
</dependency>
<dependency>
<groupId>sample2</groupId>
<artifactId>com.sample2</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/Util.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<start-class>ves.sfdc.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
You can create a new directory "lib" on your project, put your jars in this directory and then add them to your classpath.
If your IDE is IntelliJ you can follow this link:
Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
If you use another IDE you have to find on google how to add jar on your project classpath.
I used the example gs-convert-jar-to-war provided by spring-io. It describes how to generate war packaging within a spring boot project.
The spring-boot documentation allows for using own parent poms, thus omitting the predefined parent pom for all spring-boot projects. The following dependency has to be added:
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I applied this change (and only this change) to the example. Afterwards it is no longer possible to generate the war. I get following error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project gs-convert-jar-to-war: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
Here is the complete listing of the modified 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>org.springframework-sample</groupId>
<artifactId>gs-convert-jar-to-war</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<start-class>hello.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
Is there any idea to overcome the problem?
In my project I will use my own parent pom, because it defines a lot of stuff regarding the company.
You removed the parent, so you lost its declaration of the WAR plugin configuration. Here it is:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
See here for the source code.
N.B. this is not necessary with Spring Boot 2.0 parent pom and above (the war plugin version is different), or if you use the latest war plugin.
I just downloaded a Spring tutorial off the internet and am trying to run it in my local workspace. To do it, I first tried to get all the dependant jars needed by the project. I tried maven build and it failed because dependant jar's were missing from my local repository and those jar's were also missing from the remote repository(the one which my project uses)
Initially, my settings.xml only has a reference to the remote repository url which is used across the organization by various projects. I cannot expect it to be uptodate with latest jars. Can I get the remote repository names of the various utility projects fore.g for Log4j, commons logging, spring jars etc. I can then put these repository urls in my setting.xml to solve my issue.
EDIT:
I even tried "http://repo1.maven.org/maven2/" which I thought houses all the required latest jars but even this wont work.
Example..
Missing:
1) log4j:log4j:jar:1.2.13
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=log4j -DartifactId=log4j \
-Dversion=1.2.13 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) com.mkyong.core:Spring3Example:jar:1.0-SNAPSHOT
2) org.codehaus.castor:castor:jar:1.1.2.1
3) log4j:log4j:jar:1.2.13
2) xerces:xerces:jar:1.4.0
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=xerces -DartifactId=xerces \
-Dversion=1.4.0 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) com.mkyong.core:Spring3Example:jar:1.0-SNAPSHOT
2) org.codehaus.castor:castor:jar:1.1.2.1
3) xerces:xerces:jar:1.4.0
3) commons-lang:commons-lang:jar:2.5
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=commons-lang -DartifactId=commons-lang
\
-Dversion=2.5 -Dpackaging=jar -Dfile=/path/to/file
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mkyong.core</groupId>
<artifactId>Spring3Example</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Spring3Example</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Uses Castor for XML -->
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.1.2.1</version>
</dependency>
<!-- Castor need this -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
My setting .xml
<settings>
<localRepository>
C:\Repository
</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<profiles>
<profile>
<id>R2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>Log4j</id>
<url>http://central.maven.org/maven2</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>Artifact_Repository_Plugin</id>
<url>http://central.maven.org/maven2</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<pluginGroups>
<pluginGroup>com.hsbc.alm.maven.plugins</pluginGroup>
<pluginGroup>com.hsbc.alm.maven.scm</pluginGroup>
<pluginGroup>com.hsbc.alm.maven.jr2</pluginGroup>
</pluginGroups>
</settings>
Yes you are on the right path all you need to do is this or a good solution would be to generate a new archetype with the all added jar files which you have downloaded. And then using the same artifact whenever you make a similar project.
Even if you are lacking with the m2Eclipse plugin , you can use the following commands.
This can be achieved if you follow the commands as:
Move to the project and type the following command to make the project as archetype
mvn archetype:create-from-project
Install the archetype to the local repository
mvn install
Move to some directory where you wish to locate the new project created with your created archetype
mvn archetype:generate -DarchetypeCatalog=local
If a list is populated with numbers to filter then select accordingly and you are done.
This one is building successfully (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>com.test.new.project</groupId>
<artifactId>dadada</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>dadada</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Uses Castor for XML -->
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.1.2.1</version>
</dependency>
<!-- Castor need this -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>
My settings.xml :
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
</mirrors>
<profiles>
</profiles>
</settings>
Not sure why you need to alter settings.xml is there specific reason?
Environment info :
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_29
I was finally able to solve the jar download issue by defining proxy settings in my settings.xml. My company uses a proxy to communicate with outside world.Having said that, I also learnt that there is no need to define specific remote repository in settings.xml bcos maven by default searches in its own repository which mostly has all the opensource jars.
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>xyz.hk.hsbc</host>
<port>8080</port>
</proxy>
</proxies>