如何在Maven Java项目的源文件夹中添加图像? [英] How can i add images in source folder of a Maven Java Project?

查看:47
本文介绍了如何在Maven Java项目的源文件夹中添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven Java项目的源文件夹中有图像.您可以在下图中看到它.

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

如果我运行maven的install命令,当我看到生成的jar文件时,我看不到jar文件中源文件中的图像.

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.

我的maven配置如下所示.

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>

如何为我的Maven Java项目将源文件夹中的图像添加到jar文件中?

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

推荐答案

您可以使用

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>

这篇关于如何在Maven Java项目的源文件夹中添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆