从终端

时间:2017-12-01 16:22:44

标签: java maven configuration properties-file multi-module

我有一个maven项目,有两个模块,一个客户端和一个服务器。每个模块都需要从配置文件中读取一些属性。从IntelliJ IDE内部构建/运行时,它可以正常工作。但是,当我使用mvn包并从终端运行客户端和服务器时,当更改位于相应目标/类目录内的相对配置文件内的属性值时,没有任何反应。它们都继续具有初始/旧值,而不是新的/更新的值。

项目结构如下:

Project
--Client
  --src
    --main
      --java
        Client JavaCode Files
      --resources
        client.conf
  pom.xml
--Server
  --src
    --main
      --java
      Server JavaCode Files
      --resources
        server.conf
  pom.xml
pom.xml  

每个模块在其相应的资源目录中都有一个单独的配置文件。 主/父项目pom.xml如下:

<?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>gr.enomix</groupId>
<artifactId>imageClassificationWrapper</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<modules>
    <module>Server</module>
    <module>Client</module>
</modules>

<build>
    <plugins>
        <!-- any other plugins -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>1.0</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-utils</artifactId>
        <version>2.0.5</version>
        <scope>compile</scope>
    </dependency>

</dependencies>

客户端模块pom.xml是:

<?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">
<parent>
    <artifactId>imageClassificationWrapper</artifactId>
    <groupId>gr.enomix</groupId>
    <version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>gr.enomix</groupId>
<artifactId>Client</artifactId>
<packaging>jar</packaging>
<version>1.0</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>src/main/resources/client.config</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

服务器pom.xml是:

<?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">
    <parent>
        <artifactId>imageClassificationWrapper</artifactId>
        <groupId>gr.enomix</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>gr.enomix</groupId>
    <artifactId>Server</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0.0</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>src/main/resources/server.config</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

请帮助......我做错了什么?我相信一定有一些我看不到的完全明显的东西......

0 个答案:

没有答案