Maven downloads artifacts that are defined in two locations:
-
Artifact repositories defined in a
pom.xmlfile of the project. Configuring repositories inpom.xmlis not specific to Eclipse Che. For more information, see the Maven documentation about the POM. -
Artifact repositories defined in a
settings.xmlfile. By default,settings.xmlis located at`~/.m2/settings.xml.
Defining repositories in settings.xml
To specify your own artifact repositories at example.server.org, use the settings.xml file.
To do that, ensure, that settings.xml is present in all the containers that use Maven tools, in particular the Maven container and the Java plug-in container.
By default, settings.xml is located at the <home dir>/.m2 directory. Because the user home directory is not on a persistent volume, you must re-create the file each time you restart the workspace. This is a known issue, see the issue on GitHub.
A workaround is to make the file persist between the restarts of the workspace, create a directory /projects/maven/.m2, and move the settings.xml file in it. Then set the value of the user.home Java system property to /projects/maven in all your Maven containers.
-
Configure your
settings.xmlfile to use artifact repositories atexample.server.org:<settings> <profiles> <profile> <id>my-nexus</id> <pluginRepositories> <pluginRepository> <id>my-nexus-snapshots</id> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <url>http://example.server.org/repository/maven-snapshots/</url> </pluginRepository> <pluginRepository> <id>my-nexus-releases</id> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> <url>http://example.server.org/repository/maven-releases/</url> </pluginRepository> </pluginRepositories> <repositories> <repository> <id>my-nexus-snapshots</id> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <url>http://example.server.org/repository/maven-snapshots/</url> </repository> <repository> <id>my-nexus-releases</id> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> <url>http://example.server.org/repository/maven-releases/</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>my-nexus</activeProfile> </activeProfiles> </settings> -
Configure the devfile to use the
/projects/mavenvalue for theuser.homeJava system property.-
For the Java plug-in container, configure the language server start arguments preference:
components: - id: redhat/java11/latest type: chePlugin preferences: java.jdt.ls.vmargs: >- -noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication -Duser.home=/projects/maven -
For the Maven container, configure the
MAVEN_OPTSenvironment variable:mountSources: true alias: maven type: dockerimage ... env: -name: MAVEN_OPTS value: >- -Duser.home=/projects/maven
-
Using self-signed certificates in Java projects
Internal artifact repositories often do not have a self-signed (SSL) certificate signed by an authority that is trusted by default in Java. They are usually signed by an internal company authority or are self-signed. Configure your tools to accept these certificates by adding them to the Java truststore.
-
Obtain a server certificate file from the repository server. It is often a file named
tls.crt.-
Create a Java truststore file:
$ keytool -import -file tls.crt -alias nexus -keystore truststore.jks -storepass changeit Trust this certificate? [no]: yes Certificate was added to keystore Owner: CN=example.com Issuer: CN=example.com Serial number: 80ca0f6980c6019a Valid from: Thu Feb 06 11:00:29 CET 2020 until: Fri Feb 05 11:00:29 CET 2021 Certificate fingerprints: MD5: 88:3C:EC:E1:BE:57:DD:9D:46:36:8E:DD:BF:14:04:22 SHA1: 08:D8:79:D3:F8:6B:5C:3D:71:AA:23:CA:72:01:47:BD:9D:91:0A:AD SHA256: 5C:BB:66:81:44:D2:50:EE:EB:CE:D6:15:7E:63:E1:9A:71:EA:58:3F:14:01:15:4E:68:5D:71:0A:A0:31:33:29 Signature algorithm name: SHA256withRSA Subject Public Key Algorithm: 4096-bit RSA key Version: 3 Extensions: #1: ObjectId: 2.5.29.17 Criticality=false SubjectAlternativeName [ DNSName: *.apps.example.com ] Trust this certificate? [no]: yes Certificate was added to keystore -
Upload the truststore file to
/projects/maven/truststore.jksto make it available for all containers.
-
-
Add the truststore file.
-
In the Maven container:
-
Add the
javax.net.sslsystem property to theMAVEN_OPTSenvironment variable:- mountSources: true alias: maven type: dockerimage ... env: -name: MAVEN_OPTS value: >- -Duser.home=/projects/maven -Djavax.net.ssl.trustStore=/projects/truststore.jks -
Restart the workspace.
-
-
In the Java plug-in container:
In the devfile, add the
javax.net.sslsystem property for the Java language server:components: - id: redhat/java11/latest type: chePlugin preferences: java.jdt.ls.vmargs: >- -noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication -Duser.home=/projects/maven -Djavax.net.ssl.trustStore=/projects/truststore.jks [...]
-