gpt4 book ai didi

java - 如何将变量设置为数据库密码到 pom.xml

转载 作者:行者123 更新时间:2023-11-30 07:56:39 27 4
gpt4 key购买 nike

我需要将 Jenkins 变量配置为我的 pom 配置文件中的密码数据库,但是如果我设置 ${env.passwordb}(如下所示),项目不会编译并出现一些错误,但如果我将代码推送到 Jenkins,它会获取变量并完美运行项目。我需要更改什么?

<?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.company.vrs</groupId>
<artifactId>company-vrs</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>${env.urlTomcat}</url>
<path>${env.appPath}</path>
<username>${env.username}</username>
<password>${env.password}</password>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
<name>company-vrs</name>
<url>http://maven.apache.org</url>
<profiles>
<profile>
<id>dev</id>
<build>
<finalName>visitors</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.jks</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.jks</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<mainClass>com.company.vrs.config.AppConfig</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.0.RC0</version>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>asta que
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>9090</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<db.url>jdbc:postgresql://hsvvrsdev.company.com:5432/vrs_dev</db.url>
<db.username>vrsuser</db.username>
<db.password>${env.passworddb}</db.password>
<isdev>true</isdev>
<realm.metadata.file>/metadata/secureAuth_dev.xml</realm.metadata.file>
<realm.metadata.url>https://ssodev.company.com/SecureAuth68/metadata.xml</realm.metadata.url>
<realm.url.restart>https://ssodev.company.com/SecureAuth68/restart.aspx</realm.url.restart>
</properties>
</profile>
<profile>
<id>sqa</id>
<build>
<finalName>visitors_sqa</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.jks</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.jks</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<mainClass>com.company.vrs.config.AppConfig</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.0.v20140526</version>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>9090</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<db.url>jdbc:postgresql://hsvvrsdev.company.com:5432/vrs_sqa</db.url>
<db.username>vrsuser</db.username>
<db.password>vrs#2015!</db.password>
<istest>true</istest>
<realm.metadata.file>/metadata/secureAuth_dev.xml</realm.metadata.file>
<realm.metadata.url>https://ssodev.company.com/SecureAuth68/metadata.xml</realm.metadata.url>
<realm.url.restart>https://ssodev.company.com/SecureAuth68/restart.aspx</realm.url.restart>
</properties>
</profile>
<profile>
<id>pro</id>
<build>
<finalName>visitors</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.jks</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.jks</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<mainClass>com.company.vrs.config.AppConfig</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.0.v20140526</version>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>9090</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<db.url>jdbc:postgresql://hsvvrsdb.company.com:5432/vrs</db.url>
<db.username>vrsuser</db.username>
<db.password>v14r3s20150302</db.password>
<ispro>true</ispro>
<realm.metadata.file>/metadata/secureAuth_prod.xml</realm.metadata.file>
<realm.metadata.url>https://sso.company.com/visitors/metadata.xml</realm.metadata.url>
<realm.url.restart>https://sso.company.com/visitors/restart.aspx</realm.url.restart>
</properties>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-version>4.1.2.RELEASE</spring-version>
<spring-data-jpa-version>1.6.1.RELEASE</spring-data-jpa-version>
<spring-data-commons-version>1.8.1.RELEASE</spring-data-commons-version>
<hibernate-version>4.3.5.Final</hibernate-version>
<org-slf4j-version>1.7.7</org-slf4j-version>
<spring-ldap-version>2.0.1.RELEASE</spring-ldap-version>
<spring-security-version>3.2.3.RELEASE</spring-security-version>
<bonecp-version>0.8.0.RELEASE</bonecp-version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
..... many dependencies ....
</dependencies>
</project>

错误:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'env.passworddb' in string value "${env.passworddb}"

最佳答案

经过一番调查后发现 ${env.passwddb} 只存在于远程 jenkins 环境中。为了克服这个问题并仍然使用相同的配置文件配置,可能的解决方案是:

1)硬编码

在本地环境中,密码应该在属性文件中进行硬编码。一个 Remote ,占位符仍然存在。

2) 通过maven命令行传递的密码:

mvn clean package resources:testResources -Denv.passwddb=realpass

关于java - 如何将变量设置为数据库密码到 pom.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41939172/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com