Ubuntu + Eclipse + Tomcat 配置 Java Web 开发环境填坑笔记

来源:互联网 发布:数据统计软件免费 编辑:程序博客网 时间:2024/06/03 11:03

前言

从 Eclipse 官网 上下载到的 Eclipse Neon 是不带插件的, 要配置出一个 Java Web 开发环境, 尚需各种折腾. 把踩到的坑记录一下备忘.

Eclipse 基本配置:

  • 使用 shadow sock 科学上网,需要配置代理: Window -> Preferences -> General -> Network Connections

  • Help -> Install New Software, 反选 “Contact all update sites during install to find required software”

  • 配置 Java Source Attacher, 方便为各个库附加源码

Eclipse 插件:

Help -> Install New Software 如下地址:

http://download.eclipse.org/releases/neon/

选择安装如下插件:

Web, XML, Java EE and OSGi Enterprise DevelopmentEclipse Java EE Developer ToolsEclipse Java Web Developer ToolsEclipse Web Developer ToolsJST Server AdaptersWST Server Adaptersm2e-wtp - Maven Integration for WTP

Preference 中没有 Server -> Runtime Environments 选项

需要安装 JST Server AdaptersJST Server Adapters Extentions . 步骤:

  1. Help -> Install New Software
  2. 选择 Neon - http://download.eclipse.org/releases/neon
  3. Expand “Web, XML, and Java EE Development”
  4. 找到并勾选 JST Server Adapters

参考: stackoverflow_question

配置 Server -> Runtime Environments

  1. Windows → Preferences -> Server -> Runtime Environments
  2. 点击 “Add”, 选择要运行的 tomcat 版本, Next
  3. 配置 tomcat 路径. 用 apt-get install 安装的 tomcat 这个路径配置 /usr/share/tomcat7/
  4. “OK”, “Finish”

参考: askubuntu_setup_runtime_environment

Eclipse 底部没有 Servers 窗口

手动添加:
Windows -> Show View -> Other -> 查找 servers -> OK

Ubuntu Tomcat 路径

如果是用 apt-get install tomcat7 安装, 重要路径有:

/etc/tomcat{X} for configuration/usr/share/tomcat{X} for runtime, called CATALINA_HOME/usr/share/tomcat{X}-root for webapps/var/lib/tomcat{X}

如果 tomcat 在 eclipse 中始终无法启动, 尝试如下命令:

cd /usr/share/tomcat7sudo ln -s /var/lib/tomcat7/conf confsudo ln -s /etc/tomcat7/policy.d/03catalina.policy conf/catalina.policysudo ln -s /var/log/tomcat7 logssudo ln -s /var/lib/tomcat7/webapps webappssudo chmod -R 777 /usr/share/tomcat7/conf

可用如下命令查看 tomcat 的安装目录:

dpkg -L tomcat7

参考: askubuntu_tomcat_directory

经过如上配置, Eclipse 中的 Windows -> Preferences -> Tomcat 设置中可将 Tomcat 路径配置为 /usr/share/tomcat7

Eclipse Tomcat plugin 安装

Help -> Install New Software
http://tomcatplugin.sf.net/update

项目 web deployment assembly 配置 maven 依赖

运行项目时遇到下面问题:

SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListenerjava.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

解决:

  1. 右击项目名称并在弹出菜单中选择 “Properties”.
  2. 选择 “Deployment Assembly”.
  3. 点击 “Add…”.
  4. 在 Directive Type 菜单中选择 “Java Build Path Entries”, 点击 “Next”.
  5. 在 Java Build Path Entries 菜单中选择 “Maven Dependencies”, 点击 “Finish”.

参考: stackoverflow_question

Eclipse Console Log 写入本地文件

Run -> Run Configurations -> Tomcat Server -> Common -> Standard Input and Output -> Output File
在输入框内填入一个本地文件地址即可. 比如 /tmp/my_project_console_log
未来就可以愉快的使用 tail -f /tmp/my_project_console_log 在命令行看 log 了.

禁止 tomcat 开机自启

update-rc.d -f tomcat7 remove

Eclipse 自动代码提示配置

Windows -> Preferences -> Java -> Editor -> Content Assist

AutoActivation Delay 改为 20
Auto Activation triggers for java 改为 .abcdefghijklmnopqrstuvwxyz(,

Eclipse 格式化代码配置

Windows -> Preferences -> Java -> Code Style -> Formatter

格式化代码快捷键 Shift + Ctrl + F

Eclipse Customize Perspective StackOverflowError

想要配置 toolbar , 打开 Windows -> Perspective -> Customize Perspective
Eclipse 提示遇到问题, 原因是 StackOverflowError.

参考: stackoverflow_question

wget 下载 JDK

写这个是因为这里有个坑, 用 wget 不带参数直接下载 JDK 会失败. 步骤:
首先到官网找到最新的 JDK 下载地址, 找到需要的 JDK 后, 记得先点 “Accept License Agreement”, 再复制下载链接才能复制的到.

有了下载地址, 使用 wget 命令下载 JDK 时需要加一些参数才可以成功:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.rpm

把上面的 JDK 下载地址换成你想要的 JDK 地址就可以了.

参考: download_jdk_with_wget


原创文章, 转载请注明出处: http://blog.csdn.net/liuxu0703/article/details/70231512

0 0