![](/img/trans.png)
[英]What is a maven settings.xml file and how it is different from pom.xml
[英]Maven: Read encrypted password from settings.xml in pom.xml
我試圖在settings.xml中使用加密密碼。 我在我的pom.xml中有一個連接到數據庫的插件,使用sql-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.5.0</version>
</dependency>
</dependencies>
<configuration>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<url>jdbc:oracle:thin:@ip.com:1521:SID</url>
<username>someUser</username>
<password>{JucQpWS78Q0HW+3ZS/FCCGHQpwbJ8ySl2Io/ILJqf88=}</password>
</configuration>
<executions>
<execution>
<id>update-configuration</id>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>false</autocommit>
<srcFiles>
<srcFile>src/main/sql/update_sim_configuration.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
哪個工作正常如果我將密碼作為純文本放在我的pom.xml中,我想從我的settings.xml讀取此密碼,密碼以這種方式加密:
mvn -ep the_password
我在我的settings.xml中
...
<server>
<id>rms13-db-dev</id>
<username>user</username>
<password>{JucQpWS78Q0HW+3ZS/FCCGHQpwbJ8ySl2Io/ILJqf88=}</password>
</server>
...
我想'讀'解碼'rms13-db-dev'中的'密碼',我該如何實現? 或者如果您有替代版本來實現這一目標。
為此,您需要使用Maven工具加密密碼 ,然后配置sql-maven-plugin
以使用它 。 插件版本1.4不支持此功能,但1.5版本可以支持。
使用該命令創建主密碼
mvn --encrypt-master-password
從3.2.1開始,Maven將提示您輸入密碼。 完成后,使用內容創建一個名為~/.m2/settings-security.xml
的文件
<settingsSecurity> <master><!-- result of above command --></master> </settingsSecurity>
使用命令加密密碼
mvn --encrypt-password
與以前一樣,Maven會提示您輸入密碼。 然后在您的Maven設置( ~/.m2/settings.xml
,創建文件,如果它不存在),有內容
<settings> ... <servers> ... <server> <id>my.server</id> <username><!-- your DB username --></username> <password><!-- the encrypted password --></password> </server> ... </servers> ... </settings>
使用settingsKey
屬性將sql-maven-plugin
settingsKey
為您的服務器ID,在本例中為my.server
。 您需要使用插件的1.5版。
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sql-maven-plugin</artifactId> <version>1.5</version> <!-- 1.5 required --> <configuration> <settingsKey>my.server</settingsKey> <!-- id of server here --> <driver>oracle.jdbc.driver.OracleDriver</driver> <url>jdbc:oracle:thin:@ip.com:1521:SID</url> <!-- username and password are not mentioned anymore --> </configuration> </plugin>
settingsKey
。 server
條目與id
等於先前的settingsKey
值,如解釋在這里 。 ${user.home}/.m2/settings-security.xml
請參見下面的示例: <settingsSecurity>
<master>{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</master>
</settingsSecurity>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.