Установите источник данных по умолчанию в OpenLiberty с помощью плагина maven - PullRequest
1 голос
/ 29 января 2020

Я пытался установить DefaultDataSource для openliberty 20.0.0.1.

src / liberty / config / server. xml:

<?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>

И liberty-maven-plugin настроен в пом. 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>

Я использую maven-dependency-plugin для копирования дерби в $ {project.build.directory } / liberty / wlp / usr / shared / resources .

Но когда я запускаю mvn clean liberty:run -Popenliberty. Я обнаружил, что сначала копируется дерби, а затем цель liberty:run удалит target / liberty , как запретить плагину Liberty Maven удалить эту папку?

Я использовал профиль Maven openliberty для сервера свободы, проверьте полных кодов .

1 Ответ

1 голос
/ 29 января 2020

Похоже, вы запускаете команду mvn clean liberty:run -Popenliberty после предыдущего вызова сборки, который выполняет компиляцию приложения, упаковку war и т. Д. c. Запустив фазу clean в предоставленной вами команде, Maven удалит папку target и, следовательно, вывод всех предыдущих вызовов. Это не относится к поведению подключаемого модуля Liberty Maven.

В репозитории подключаемого модуля Liberty Maven открыт вопрос , поддерживающий копирование зависимостей в каталог общих ресурсов.

В качестве обходного пути вы можете сделать:

mvn clean install liberty:create dependency:copy liberty:run -Popenliberty

Таким образом, LMP создаст сервер, затем скопирует зависимость Derby и запустит сервер на переднем плане.

...