使用IntelliJ IDEA 创建maven web项目

IntelliJ IDEA 创建maven web项目2(6)


IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)

<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。如上。

IntelliJ IDEA 创建maven web项目2(6)

点击Enable Auto Import
IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>
IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)

资源文件的访问
IntelliJ IDEA 创建maven web项目2(6)
IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)

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");

IntelliJ IDEA 创建maven web项目2(6)

在需要测试的类中如下图所示:

IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)IntelliJ IDEA 创建maven web项目2(6)

相关文章: