我是用可視化開發簡單的java應用程序。我必須用maven把它打包成jar。我的項目結構是:
SRC
---主要
-------- java的
----------- com.chess
------- - 資源
-----------圖像
可執行jar無法看到圖像
我試圖使用像:Images \ image.jpg但它的缺失。我如何使用圖像?
這是我的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>ChessApp</groupId>
<artifactId>ChessApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.chess.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
你在罐子裏手動看過嗎?你如何訪問圖像? –
我試圖訪問像:「Images \\ images.jpg」它將圖像文件夾與com和META-INF文件夾放在一個圖層 – Srw
然後,您需要顯示您如何訪問圖像。你應該使用類加載器。這與maven無關。 –