运行学长的Eclipse工程,遭遇了无数的坑,整理如下,造福后人.
直接从Git导入工程
配置GitHub账号
打开
Eclipse,进入整个Eclipse的PropertiesType “git” in the search bar, then choose that path ‘Team > Git > Configuration’. Click ‘Add Entry…’.
Enter
user.nameas the Key, and your GitHub username as the Value, then add another entry withuser.emailas the Key and your corresponding email as the Value. (就是GitHub的用户名和邮箱)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.
- Open Eclipse, with E-Git installed (you will quickly find out if you have an older version without it).
- In Eclipse, choose ‘File’ (top left), then ‘Import…’
- In the dialog that opens, choose ‘Git > Projects from Git’ and click ‘Next’
- Click on ‘Clone URI’, then click ‘Next’ 复制Git上的
https地址(而不是ssh) - 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标签页中(只是有了repository,依然需要) 导入工程
在刚刚clone下来的repository上右键,
Import Projects选择General->Existing projects from file system or archive(或是另一个),才能检测到project
Build Path 配置
更换JDK版本,可以在
Eclipse的Properties中将java->installed JDKs更换(这种方法修改的是workplace default JDK),也可以在Project Properties中修改package的路径问题
代码里定义的包名是
com.yancloud.sc.servlet但是直接打开工程后把src.com.yancloud.sc.servlet直接缩到了一起,需要改Build PATH中的source,把它们拆成两级目录缺少 javax, websocket等包,在Tomcat的
lib文件夹下有,我直接把所有的包都加进去了
Tomcat Server 配置
在Eclipse中安装Tomcat Server
https://www.baeldung.com/eclipse-tomcat
这个链接的2步骤
项目
Properties->Facets选中
Dynamic Web ModuleJavaJavaScript三项,注意Java的版本也要和Library的版本对应上执行上面链接4
执行代码
可以直接运行test文件夹下的测试程序(含有main函数,可以独立运行)
我运行时出现了has been compiled by a more recent version of the Java Runtime错误,后来发现是project的Properties-> Java Compiler没有改成对应的JDK版本