- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用 pom 中的属性设置 glassfish-resources.xml 中 jdbc-connection-pool 属性的值。
例如我的pom.xml
...
<profiles>
<profile>
<id>dev</id>
<properties>
<database.dbname>Xpto</database.dbname>
...
</properties>
</profile>
...
</profiles>
...
还有 glassfish-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<custom-resource res-type="java.util.Properties" jndi-name="jndi/iprofile"
factory-class="org.glassfish.resources.custom.factory.PropertiesFactory">
<property name="name" value="${webapp.profile}" />
</custom-resource>
<jdbc-resource enabled="true" jndi-name="jdbc/users" object-type="user" pool-name="MY-POOL">
<description/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.microsoft.sqlserver.jdbc.SQLServerXADataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="MY-POOL" non-transactional-connections="false" ping="false" pool-resize-quantity="2" pooling="true" res-type="javax.sql.XADataSource" statement-cache-size="0" statement-leak-reclaim="false" statement-leak-timeout-in-seconds="0" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value=""/>
<property name="PortNumber" value=""/>
<property name="DatabaseName" value=""/>
<property name="User" value=""/>
<property name="Password" value=""/>
</jdbc-connection-pool>
我想使用 pom.xml 中定义的值 Xpto 设置 DatabaseName 属性。其他配置文件的database.dbname 属性具有不同的值。
最佳答案
您可以使用 maven-replacer-plugin 来解决此类任务。它可用于替换文件中的值。
这是一个例子:
像以前一样定义您的属性:
<properties>
<database.dbname>Xpto</database.dbname>
</properties>
将 glassfish-resources.xml
中要替换的属性更改为如下所示:
<property name="DatabaseName" value="DATABASENAME"/>
值DATABASENAME
用于替换。您可以使用任何值,但它在您要修改的文件中必须是唯一的。
将 maven-war-plugin
的配置更改为如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<warSourceDirectory>${project.build.directory}/${project.build.finalName}</warSourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
Currently, the replacer plugin needs access to a target resource before it is packaged into an archive. However, standard WAR packaging does not expose web resources (anything under src/main/webapp) for use in other plugins and runs as a single execution. Fortunately, we can invoke war:exploded to copy these resources earlier in the build lifecycle so that they can be used by the maven-replacer-plugin. The standard package usage will then use the modified web resources when creating the WAR artifact.
将 maven-replacer-plugin
的以下配置添加到 pom.xml
中:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>target/${project.build.finalName}/WEB-INF/glassfish-resources.xml</file>
<token>DATABASENAME</token>
<value>${database.dbname}</value>
</configuration>
</plugin>
如您所见,标记 DATABASENAME
被替换为 ${database.dbname}
的值。这是在 prepare-package
阶段完成的,即在将 Web 应用程序内容复制到分解的 WAR 目录之后,但在将该目录打包为 WAR 文件之前。
如果替换不起作用,您可能需要将 maven-war-plugin
降级到版本 2.0.1。
如果您想替换多个不同的值,您可以将配置中的 token 和值替换为如下内容:
<replacements>
<replacement>
<token>DATABASENAME</token>
<value>${database.dbname}</value>
</replacement>
</replacements>
另请参阅:
关于java - 从 glassfish-resources.xml 访问 pom 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24506939/
如何将 glassfish 服务器的所有配置保存到另一个 glassfish 服务器? 最佳答案 看到这个问题:GlassFish v3 - portability of settings glass
我安装了 JDK 1.6 b45 并尝试运行 glassfish v2.2。当我尝试启动它时,总是会抛出以下错误: [#|2013-06-18T08:50:20.196+0200|WARNING|su
glassfish 访问日志位于哪里?我希望它们位于domains/domainX/logs 中。我需要更改设置才能激活访问日志记录吗? 谢谢 最佳答案 路径似乎正确,请查看此链接 http://bl
我想在没有互联网连接的情况下升级 Glassfish。但我已经下载了最新版本。 我已完成以下步骤, 例如。 galssfish-3.0 是旧版本,glassfish-3.1 是新版本。 步骤:1我刚刚
我在 Windows 8.1 中启动 glassfishs 服务时遇到问题 我得到了这个错误: c:\glassfishv3\bin>asadmin 创建服务 Found the Windows Se
我们最近切换到 Glassfish 3.1.2.2,并将几个 Web 应用程序打包为 war 文件。有时,这些应用程序所需的上下文根不同于文件名。 回到我们使用 Weblogic 时,我们通过在 we
我只是测试在 glassfish 服务器队列上发送消息,因此我在 glassfish 服务器上创建了 JMSResource,如下所示: 现在我已经在 Netbeans IDE 中创建了一个 Java
我想知道 GlassFish 项目是死了还是还活着?从一开始,我就非常喜欢玻璃鱼。我开始使用 GlassFish2 进行项目,并且有很多客户使用 GlassFish3。 几个月以来,我尝试将我的一些项
我使用 Glassfish 应用服务器,根据 README 文件,它只是说打开 CMD,键入一些命令,但我得到了 Nullpointer。我需要有人帮助我。我在 Windows 上。 asadmin
我最近将 Glassfish 从 3.1.2 更新到 4.0,并想设置一个我以前在我的应用程序上使用过的 JDBCRealm,它使用基于 FORM 的身份验证。密码在数据库中使用 SHA-256 散列
您如何确定正在运行哪个版本的GlassFish服务器? 该命令: /var/glassfish/bin/asadmin version ...回: Version = Sun Java System
所以,基本上: 在 RHEL 6.2 和 Java 6 上有一个独立的(无集群)Glassfish 3.1.2 新安装,没有任何部署的应用程序(真正的新安装)。 我第一次在服务器上启动了默认域 dom
我有一个带有 Glassfish 应用程序服务器的 EJB WEB 应用程序。 现在我想要像这样“/”的上下文根。 我当前的网址是“http://localhost:8080/Make ” 但我想要这
我正在尝试在 Windows 7 64 位上安装带有 Eclipse 的 GlassFish 4。一切正常,但是当我尝试设置服务器 root 时会发生以下情况(目录存在): 最佳答案 Glassfis
如何使用密码文件更改 Glassfish 域的管理员密码?我知道在提示时手动输入密码的传统方法。 但是,我想使用脚本更改管理员密码,而无需手动输入密码。 最佳答案 这是可能的,但如果您想以最简单的方式
我想在Glassfish 3.1中设置JDBC领域,并且关注此博客http://blog.gamatam.com/2009/11/jdbc-realm-setup-with-glassfish-v3.
我在远程机器上运行 Glassfish。是否有从命令提示符以 Debug模式启动 GF 的命令?远程机器运行 Ubuntu 10.04,我的机器运行 Windows 7(不确定这是否重要)。 我连接没
我们每周都会发布新的生产代码,Glassfish 没有遇到任何问题。这个周末我们不得不在我们的托管服务提供商处移动机架。没有任何代码更改(它们只是关闭电源、移动、重新安装和打开电源)但是我们在一个新的
对于生产环境,Apache Geronimo 是否更适合使用 ActiveMQ、Derby、Solr 的应用程序? 最佳答案 简而言之,如果您想要一个轻量级部署容器,请使用 Geronimo(它基于
我正在尝试设置一个备用文档根目录,以便提供上传的文档。我已将以下内容包含在我的 glassfish web xml 中 /dom 然后,我在名为 cars.pdf 的 Test 文件夹中存储了一
我是一名优秀的程序员,十分优秀!