Maven是很很難。我想引用我的代碼中的資源。但我不能。如何從Maven項目獲取資源
我有一個在Eclipse中設置的項目。在這裏面我有以下結構
src
---main
--------java
------------myclasses
-------resources
------------sometextfiles.txt
pom.xml中的相關部分如下:
<build>
<finalName>MyProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>main.java.Console.TBB_SQLBuilder</mainClass>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
當我Maven構建從乾淨的Eclipse安裝通常是目標文件夾不產生資源文件夾。其他人遭受的錯誤。我認爲這可以通過在目標文件夾中手動創建資源文件夾來彌補,但這不是很有用。但即使我做到這一點我似乎不能夠使用的資源:
我的代碼:
public class Checkers {
ArrayList<String> che2=new ArrayList<String>();
static URL dictionary;
String n=null;
public Checkers() {
}
public static String FindNReplace(String n) throws IOException, URISyntaxException{
BufferedReader reader = new BufferedReader(new InputStreamReader(ClassLoader.class.getResourceAsStream("FindNReplaceDictionary.txt")),2048);
String [] split=null;
ArrayList<String> orig= new ArrayList<String>();
String [] orig_arr=null;
ArrayList<String> newDoc= new ArrayList<String>();
String [] newDoc_arr=null;
StringBuilder sb = new StringBuilder();
String line = reader.readLine();
while (line != null) {
split=line.split(":");
System.out.println("SPLIT"+split);
}
}
}
我也試過用FindNReplaceDictionary.txt領先「 /「但沒有喜樂。
因此,處理我的困惑這裏是我的問題 1.我如何引用Eclipse中的資源,以便我可以運行它作爲一個Java項目至少 2.如何一次引用資源Maven項目已經經歷了構建乾淨安裝 3.我是否需要改變它作爲一個Java項目和做一個Maven構建之間的任何變化
是的我對整個事情感到困惑。
無資源文件夾應該被創建,無論資源文件夾中的任何內容都被複制到將成爲類路徑根目錄的位置。本地客戶端應用程序中的jar的根,Web應用程序中的WEB-INF/classes。 – Gimby