快速搭建开发环境(Vs Code)

使用VS Code + Maven 快速搭建简易开发环境

(Maven很强大,这里我是用Maven主要目的,省去了对jar包的管理)

(VS Code也很强大,这里我是用VS Code主要目的,感觉比 Eclipse更轻量级)

 

■环境搭建

1.Meaven中,setting文件的设定

指定本地仓库,和镜像库(这里使用阿里的)

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/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>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
  </profiles>
</settings>

2.POM文件的设定

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
            http://maven.apache.org/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     = "https://www.baidu.com";

    public static void main(String[] args) {

        DefaultHttpClient httpclient = new DefaultHttpClient();

        // Login requests must be POSTs
        HttpGet httpGet = new HttpGet(LOGINURL);
        HttpResponse response = null;

        try {
            // Execute the login POST request
            response = httpclient.execute(httpGet);
        } catch (ClientProtocolException cpException) {
            // Handle protocol exception
        } catch (IOException ioException) {
            // Handle system IO exception
        }

        // verify response is HTTP OK
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            System.out.println("Error authenticating to Force.com: "+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 www.baidu.com的效果

----------

5.6查找(使用查找功能,可以快速找到配置文件里面配置的一些值)

 

■设置与快捷键的使用

1.导入类

 Shift + Alt + o

Eclipse中是(Ctrl  + Shirt + o)

2.终端 控制台中,输出最大行数设定

3.todo

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值