Eclipse Web Application 环境搭建

运行学长的Eclipse工程,遭遇了无数的坑,整理如下,造福后人.

直接从Git导入工程

  1. 配置GitHub账号

    打开Eclipse,进入整个EclipseProperties

    Type “git” in the search bar, then choose that path ‘Team > Git > Configuration’. Click ‘Add Entry…’.

    Enter user.name as the Key, and your GitHub username as the Value, then add another entry with user.email as the Key and your corresponding email as the Value. (就是GitHub的用户名和邮箱)

  2. Import the repo into Eclipse

    We don’t yet physically have a local copy of the repo, but Eclipse is going to take care of the details for us.

    1. Open Eclipse, with E-Git installed (you will quickly find out if you have an older version without it).
    2. In Eclipse, choose ‘File’ (top left), then ‘Import…’
    3. In the dialog that opens, choose ‘Git > Projects from Git’ and click ‘Next’
    4. Click on ‘Clone URI’, then click ‘Next’ 复制Git上的https地址(而不是ssh)
    5. Here’s where some magic happens: on this next screen the details should already be filled out for you, as shown below. Ensure that your GitHub username and password are entered under ‘Authentication’, and click Next.

    会显示在Git Repositories标签页中

  3. (只是有了repository,依然需要) 导入工程

    在刚刚clone下来的repository上右键,Import Projects选择General->Existing projects from file system or archive(或是另一个),才能检测到project

Build Path 配置

  1. 更换JDK版本,可以在EclipseProperties中将java-> installed JDKs更换(这种方法修改的是workplace default JDK),也可以在Project Properties中修改

  2. package的路径问题

    代码里定义的包名是com.yancloud.sc.servlet但是直接打开工程后把src.com.yancloud.sc.servlet直接缩到了一起,需要改Build PATH中的source,把它们拆成两级目录

  3. 缺少 javax, websocket等包,在Tomcat的lib文件夹下有,我直接把所有的包都加进去了

Tomcat Server 配置

  1. 在Eclipse中安装Tomcat Server

    https://www.baeldung.com/eclipse-tomcat

    这个链接的2步骤

  2. 项目Properties-> Facets

    选中 Dynamic Web Module Java JavaScript三项,注意Java的版本也要和Library的版本对应上

  3. 执行上面链接4

执行代码

可以直接运行test文件夹下的测试程序(含有main函数,可以独立运行)

我运行时出现了has been compiled by a more recent version of the Java Runtime错误,后来发现是project的Properties-> Java Compiler没有改成对应的JDK版本

0%