将文件绑定到Maven内置的EAR中

时间:2019-01-10 05:32:54

标签: java maven maven-2 maven-plugin maven-resources-plugin

下面是我的项目结构。 enter image description here

在构建MainProject时,我需要将文件\ MainProject \ src \ non-packaged-resources复制到\ MainProject \ sub-project2 \ sub-project2-web \ src \ main \ resources位置。 以下是我的sub-project2-web pom文件的build部分,但是在构建时不会复制该文件。

    <build>
    <finalName>sub-project2-web</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <warSourceExcludes>**/.copyarea.db</warSourceExcludes>
                <packagingExcludes>**/.copyarea.db</packagingExcludes>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <!-- here the phase you need -->
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>/src/main/resources</outputDirectory>
                        <resources>
                            <resource>
                                <directory>/src/non-packaged-resources</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

在查看构建日志时,它会跳过正在复制的文件,并出现以下错误

skip non existing resourceDirectory

但是Maven构建成功。 目标是将\ MainProject \ src \ non-packaged-resources中存在的文件绑定到构建Maven项目的所有耳朵(sub-project1.ear,sub-project2.ear)。首先,我尝试仅在sub-project2-web中对此进行测试。 请根据此要求提供有关如何提供正确路径的建议。 我正在使用maven 2.2.1版本(项目是基于此版本的。)

2 个答案:

答案 0 :(得分:1)

参照项目基本目录定义路径,如下所示。

   Observable.timer(delay, TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(aLong -> {
           // Execute code here
        }, Throwable::printStackTrace);

class segmentatiomn:

    CLUSTERS = None
    IMAGE = None
    COLORS = None
    LABELS = None
    def _init_(self,image,clusters=2):
     self.CLUSTERS = clusters
     self.IMAGE = image
    def dominantColors(self):
        # read image
        img = cv2.imread(self.IMAGE)

        # convert to rgb from bgr
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

        # reshaping to a list of pixels
        img = img.reshape((img.shape[0] * img.shape[1], 3))

        # save image after operations
        self.IMAGE = img

        # using k-means to cluster pixels
        kmeans = KMeans(n_clusters=self.CLUSTERS)
        kmeans.fit(img)

        # the cluster centers are our dominant colors.
        self.COLORS = kmeans.cluster_centers_
        # save labels
        self.LABELS = kmeans.labels_

        # returning after converting to integer from float
        return self.COLORS.astype(float)

img = 'img'
clusters = 2
dc = segmentatiomn(img, clusters)
colors = dominantColors()
print(colors)

然后将其添加到<outputDirectory>${project.basedir}/sub-project2/sub-project2-web/src/main/resources</outputDirectory> 的{​​{1}}文件中。

<directory>${project.basedir}/src/non-packaged-resources</directory>

答案 1 :(得分:0)

基于以上答案,我找到了获取父目录和基础目录位置的正确方法。下面为我​​工作。

std::thread thread_read(read_value, std::ref(data));
std::thread thread_print(print_value, std::cref(data));