简体   繁体   中英

Customize maven assembly plugin

I like Maven quite a lot as it makes some things really easy, but it is sometimes hard for me to deal with some parts of it... Although I searched the web, I don't get it to work as I want.

Here's my current assembly configuration:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <finalName>${project.name}_${project.version}</finalName>
                <outputDirectory>C:\temp\FundSteward\</outputDirectory>
                <appendAssemblyId>false</appendAssemblyId>
                <archive>
                    <manifest>
                        <mainClass>lu.aspecta.fundSteward.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

It creates a runnable jar in the specified destination folder; that's exactly what I wanted so far. Now, I would like to have the log4j.properties file saved next to the jar file in the destination folder so that I can adapt it without packing the jar again. Furthermore, it should not be packed into the jar but I would like to keep in in /src/main/resources (as usual).

I have already tried different ways (with different assembly files (would be the preferred way), other configurations, ...) but I don't manage to get it working as I want.

Every help or even a little hint is highly appreciated.

Best regards, JR

Just in case someone's interested, here's what I did to resolve this issue. Parts scrapped from multiple SO sources. :)

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
                <targetPath>${project.build.directory}/${project.build.finalName}</targetPath>
                    <includes>
                        <include>log4j.properties</include>
                    </includes>
        </resource>
    </resources>

    ...

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
            <finalName>${project.name}</finalName>
            <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
                <appendAssemblyId>false</appendAssemblyId>
                <archive>
                    <manifest>
                        <mainClass>com.my.app.MyMain</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>.</Class-Path>
                    </manifestEntries>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
</build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM