问题1: maven 中资源文件的加载
在pom.xml 文件中配置
<resources>
<resource>
<directory>src/main/java/web/mc</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource> //配置文件的路径
<resource>
<directory>src/main/java/business/impl</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
在java文件中读取的时候
maven 项目中文件的获取ClassLoader classloader = Thread.currentThread() .getContextClassLoader();
InputStream inputStream = classloader .getResourceAsStream("com/huashu/boss/busi/mc/impl/data.properties");
我们后面的WEB程序,里面的jar、resources都是由Tomcat内部来加载的,所以你在代码中动态加载jar、资源文件的时候,首先应该是使用Thread.currentThread().getContextClassLoader()。如果你使用Test.class.getClassLoader(),可能会导致和当前线程所运行的类加载器不一致(因为Java天生的多线程)。
问题2 eclipse中相关的maven命令说明:
maven clean 清除目标目录中的生成结果 target 目录下的内容
maven bulid
maven install
是将你打好的jar包安装到你的本地库中