通过 maven 插件在 OpenLiberty 中安装默认数据源

2024-04-15

我试图为 openliberty 20.0.0.1 设置 DefaultDataSource。

The src/liberty/config/server.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>javaee-8.0</feature>
    </featureManager>

    <!-- This template enables security. To get the full use of all the capabilities, a keystore and user registry are required. -->

    <!-- For the keystore, default keys are generated and stored in a keystore. To provide the keystore password, generate an 
         encoded password using bin/securityUtility encode and add it below in the password attribute of the keyStore element. 
         Then uncomment the keyStore element. -->
    <!--
    <keyStore password=""/> 
    -->

    <!--For a user registry configuration, configure your user registry. For example, configure a basic user registry using the
        basicRegistry element. Specify your own user name below in the name attribute of the user element. For the password, 
        generate an encoded password using bin/securityUtility encode and add it in the password attribute of the user element. 
        Then uncomment the user element. -->
    <basicRegistry id="basic" realm="BasicRealm"> 
        <!-- <user name="yourUserName" password="" />  --> 
    </basicRegistry>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

    <!-- Derby Library Configuration -->    
    <library id="derbyJDBCLib">
      <fileset dir="${shared.resource.dir}" includes="derby*.jar"/>
    </library>

    <!-- Datasource Configuration -->
    <!-- remove jndiName="" to serve java:comp/DefaultDataSource for Java EE 7 or above -->
    <dataSource id="DefaultDataSource">
      <jdbcDriver libraryRef="derbyJDBCLib" />
      <properties.derby.embedded databaseName="taskdb" createDatabase="create"/>
    </dataSource>

</server>

And the liberty-maven-plugin配置在pom.xml.

 <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.1.1</version>
                        <executions>
                            <execution>
                                <id>copy</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>   
                            </execution>
                        </executions>                     
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.derby</groupId>
                                    <artifactId>derby</artifactId>
                                    <version>10.14.2.0</version>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/liberty/wlp/usr/shared/resources</outputDirectory>
                        </configuration>                                    
                    </plugin>             
                    <!-- Enable liberty-maven-plugin -->
                    <plugin>
                        <groupId>io.openliberty.tools</groupId>
                        <artifactId>liberty-maven-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <libertyRuntimeVersion>20.0.0.1</libertyRuntimeVersion>
                        </configuration>
                    </plugin>

I use maven-dependency-plugin将德比复制到${project.build.directory}/liberty/wlp/usr/shared/resources.

但当我跑步时mvn clean liberty:run -Popenliberty。我发现德比是先被复制的,然后是liberty:run目标将移除目标/自由,如何防止liberty maven插件删除这个文件夹?

我使用了 Maven 配置文件开放自由对于 Liberty 服务器,请检查完整代码 https://github.com/hantsy/jakartaee-mvc-sample/blob/master/pom.xml.


从...开始3.3版本 https://github.com/OpenLiberty/ci.maven/releases/tag/liberty-maven-3.3Liberty Maven 插件有一个copyDependencies范围:

pom.xml

<plugins>
  <plugin>
    <groupId>io.openliberty.tools</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <version>3.3.4</version> 
    <configuration>
      <!-- Usually best to add configuration at the plugin level rather than trying to configure particular executions -->
      <copyDependencies>
        <dependencyGroup>
          <!-- Relative to server config directory -->
          <location>lib/global/jdbc</location>
          <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
          </dependency>
        </dependencyGroup>
      </copyDependencies>
    </configuration>
      ...

服务器.xml

...
<!-- Derby Library Configuration -->    
<library id="derbyJDBCLib">
  <fileset dir="${server.config.dir}/lib/global/jdbc" includes="derby*.jar"/>
</library>
...

See 文档 https://github.com/OpenLiberty/ci.maven/blob/master/docs/common-server-parameters.md#copying-dependencies-with-liberty-maven-plugin了解更多详情。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 maven 插件在 OpenLiberty 中安装默认数据源 的相关文章

随机推荐