使用IntelliJ IDEA 创建maven web项目
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<localRepository>D:\repository</localRepository>
</settings>
从网上下载Maven3.3.9版本(可以更高),然后改写里面settings.xml。如上。
点击Enable Auto Import
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
2.5
</version>
</dependency>
资源文件的访问
Properties properties =
new
Properties()
;
properties.load(getClass().getResourceAsStream(
"/mydb.properties"
))
;
out.write(
"url:"
+properties.getProperty(
"jdbc_url"
)+
"
\n
"
)
;
out.write(
"username:"
+properties.getProperty(
"jdbc_username"
)+
"
\n
"
)
;
out.write(
"jdbc_password:"
+properties.getProperty(
"jdbc_password"
)+
"
\n
"
)
;
在需要测试的类中如下图所示: