'Karaf settings.xml
Currently we are using Apache Karaf v4.2.8 installed / running as a windows service.
We use AWS code artefact as our mvn repository, the issue here is that tokens only last for 12hrs meaning every time we need to use a new token we need to restart the windows service / karaf in order it to pick up the token and authenticate correctly (only an issue if we need to install a new feature)
Am I missing something here? is there a way to use an environment variable or something?
Solution 1:[1]
Karaf contains maven feature you can install to manage your Maven repositories:
karaf@root()> feature:install maven
For example:
karaf@root()> maven:repository-list
== Remote repositories
ID ? URL
????????????????????????????????????????????????????????????????????????????????????????????????
central ? https://repo1.maven.org/maven2/
apache ? https://repository.apache.org/content/groups/snapshots-group/
ops4j.sonatype.snapshots.deploy ? https://oss.sonatype.org/content/repositories/ops4j-snapshots/
== Default repositories
ID ? URL
?????????????????????????????????????????????????????????????????????????
system.repository ? file:/data/servers/apache-karaf-4.3.6/system/
kar.repository ? file:/data/servers/apache-karaf-4.3.6/data/kar/
child.system.repository ? file:/data/servers/apache-karaf-4.3.6/system/
You can change configuration of any remote maven repository using maven:repository-change command.
By default, your Maven Master password (see mvn -emp) is taken from ~/.m2/settings-security.xml, but if you invoke maven:password -emp -p you can set new master password and underneath Karaf will create new settings-security.xml and point your etc/org.ops4j.pax.url.mvn.cfg to this file. For example:
karaf@root()> maven:password -emp -p
Maven security settings will be stored in new file. This file will be used in org.ops4j.pax.url.mvn.security property. Continue? (y/N) y
Master password to encrypt: ********
Encrypted master password: {xxx}
New security settings stored in "/data/servers/apache-karaf-4.3.6/data/cache/bundle52/data/maven-security-settings-1651245247562.xml"
maven-security-settings-1651245247562.xml looks like this:
$ cat /data/servers/apache-karaf-4.3.6/data/cache/bundle52/data/maven-security-settings-1651245247562.xml
<?xml version="1.0" encoding="UTF-8"?>
<settingsSecurity>
<master>{xxx}</master>
</settingsSecurity>
And etc/org.ops4j.pax.url.mvn.cfg contains TWO new properties:
org.ops4j.pax.url.mvn.settings = /data/servers/apache-karaf-4.3.6/data/cache/bundle52/data/maven-settings-1651244980542.xml
org.ops4j.pax.url.mvn.security = /data/servers/apache-karaf-4.3.6/data/cache/bundle52/data/maven-security-settings-1651245247562.xml
The 2nd one contains your new master password and the first one is a copy of your existing ~/.m2/settings.xml
You can change a repository password using:
karaf@root()> maven:repository-change -id central --username test --password test
Maven settings will be updated and org.ops4j.pax.url.mvn.settings property will change. Continue? (y/N) y
New settings stored in "/data/servers/apache-karaf-4.3.6/data/cache/bundle52/data/maven-settings-1651245438306.xml"
maven-settings-1651245438306.xml was created and Maven Central now looks like this:
<server>
<username>test</username>
<password>test</password>
<id>central</id>
</server>
You can also use encrypted password. First obtain it:
karaf@root()> maven:password -ep
Password to encrypt: ****
Encrypted password: {xxx}
You can use this encrypted password when defining repositories and proxies
And use it:
karaf@root()> maven:repository-change -id central --username test --password '{xxx}'
Maven settings will be updated and org.ops4j.pax.url.mvn.settings property will change. Continue? (y/N) y
New settings stored in "/data/servers/apache-karaf-4.3.6/data/cache/bundle52/data/maven-settings-1651245586888.xml"
Thanks to master password created earlier, everything is fine:
karaf@root()> maven:repository-list -x
== Remote repositories
ID ? URL ? Username ? Password
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
central ? https://repo1.maven.org/maven2/ ? test ? test
and maven-settings-1651245586888.xml contains:
<server>
<username>test</username>
<password>{xxx}</password>
<id>central</id>
</server>
These commands simply operate on Configuration Admin and org.ops4j.pax.url.mvn PID. But they give you transparent handling of settings.xml underneath.
See documentation about Karaf Maven commands here: https://karaf.apache.org/manual/latest/#_maven_configuration_commands
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Grzegorz Grzybek |
