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