How can i add images in source folder of a Maven Java Project?

為{幸葍}努か 提交于 2021-01-28 07:34:32

问题


I have images in source folder of a maven java project. you can see it in the below image.

if i run install command of maven, when i see generated jar file , i could not see the images in sources in the jar file.

My maven configuration is like below.

    <plugins>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass></mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

How can i add images in source folder to jar file for my maven java project ?


回答1:


You can use the resources plugin to add those files into your JAR. By default, Maven will look for your project's resources under src/main/resources. So if you move your images there, they should be automatically included. However, if you want to include a different folder, you can tell Maven with:

<project>
 ...
 <build>
   ...
   <resources>
     <resource>
       <directory>[your folder here]</directory>
       <includes><include>*.png</include></includes>
     </resource>
   </resources>
   ...
 </build>
 ...
</project>


来源:https://stackoverflow.com/questions/45751561/how-can-i-add-images-in-source-folder-of-a-maven-java-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!