使用VS Code + Maven 快速搭建简易开发环境
(Maven很强大,这里我是用Maven主要目的,省去了对jar包的管理)
(VS Code也很强大,这里我是用VS Code主要目的,感觉比 Eclipse更轻量级)
■环境搭建
1.Meaven中,setting文件的设定
指定本地仓库,和镜像库(这里使用阿里的)
<?xml version="1.0" encoding="UTF-8"?><settings xmlns="/SETTINGS/1.0.0"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/SETTINGS/1.0.0 /xsd/settings-1.0.0.xsd"><localRepository>C:\userName\Dev\Maven\repository</localRepository><pluginGroups></pluginGroups><proxies></proxies><servers></servers><mirrors><mirror><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>nexus-aliyun</name><url>/nexus/content/groups/public</url></mirror></mirrors><profiles></profiles></settings>
2.POM文件的设定
<project xmlns="/POM/4.0.0"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/POM/4.0.0/xsd/maven-4.0.0.xsd"><!-- 模型版本。maven2.0必须是这样写,现在是maven2唯一支持的版本 --> <modelVersion>4.0.0</modelVersion> <!-- 公司或者组织的唯一标志,并且配置时生成的路径也是由此生成, 如com.winner.trade,maven会将该项目打成的jar包放本地路径:/com/winner/trade --> <groupId>com.sxz.trade</groupId> <!-- 本项目的唯一ID,一个groupId下面可能多个项目,就是靠artifactId来区分的 --> <artifactId>sxzDemo</artifactId> <!-- 本项目目前所处的版本号 --> <version>1.0.0-SNAPSHOT</version> <!-- 打包的机制,如pom,jar, maven-plugin, ejb, war, ear, rar, par,默认为jar --> <packaging>jar</packaging> <!-- 为pom定义一些常量,在pom中的其它地方可以直接引用 使用方式 如下 :${file.encoding} --> <properties><file.encoding>UTF-8</file.encoding><java.source.version>1.8</java.source.version><java.target.version>1.8</java.target.version></properties> <!-- 定义本项目的依赖关系 --> <dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient-cache</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.1.2</version> </dependency> </dependencies> </project>
3. IDE VSCode 中setting.json (不具有共同性)
{"java.configuration.updateBuildConfiguration": "interactive","java.home": "C:\\Program Files\\Java\\jdk1.8.0_191","java.configuration.maven.userSettings": "C:\\UserName\\Program Files\\apache-maven-3.6.3\\conf\\settings.xml","maven.terminal.customEnv": [ {"environmentVariable": "JAVA_HOME","value": "C:\\Program Files\\Java\\jdk1.8.0_191"}],"files.exclude": {"**/.classpath": true,"**/.project": true,"**/.settings": true,"**/.factorypath": true},"java.dependency.packagePresentation": "flat","maven.view": "flat"}
使用 Ctrl + shift +t 可以调用出以上窗口
4.一个简单的java类
package com.sxz.timecontroal;import java.io.IOException;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.util.EntityUtils;import org.apache.http.client.ClientProtocolException;public class CheckTimeWithNet {static final String LOGINURL= "";public static void main(String[] args) {DefaultHttpClient httpclient = new DefaultHttpClient();// Login requests must be POSTsHttpGet httpGet = new HttpGet(LOGINURL);HttpResponse response = null;try {// Execute the login POST requestresponse = httpclient.execute(httpGet);} catch (ClientProtocolException cpException) {// Handle protocol exception} catch (IOException ioException) {// Handle system IO exception}// verify response is HTTP OKfinal int statusCode = response.getStatusLine().getStatusCode();if (statusCode != HttpStatus.SC_OK) {System.out.println("Error authenticating to : "+statusCode);// Error is in EntityUtils.toString(response.getEntity()) return;}String getResult = null;try {getResult = EntityUtils.toString(response.getEntity(),"UTF-8");} catch (IOException ioException) {// Handle system IO exception}System.out.println(response.getStatusLine());System.out.println(getResult);}}
---------
5.其他,界面显示
5.1导入的jar包
5.2 编译使用的jar和jre不一致警号,不过暂时没有影响(有待解决)
VS code中的工程会和eclipse的的工程一样,
生成一个.classpath的文件
这个文件中,有对编译环境的指定,不过修改之后(1.5⇒1.8),出现了更多的错误
5.3设定窗口显示
在这里右键窗口,便可以选择想要显示的内容
5.4运行的结果
5.5命令行 curl 的效果
----------
5.6查找(使用查找功能,可以快速找到配置文件里面配置的一些值)
■设置与快捷键的使用
1.导入类
Shift + Alt + o
Eclipse中是(Ctrl + Shirt + o)
2.终端 控制台中,输出最大行数设定
3.todo