http://www.tuicool.com/articles/NBzAzy

江湖传闻,scala开发的最佳利器乃 JetBrains 的神作 IntelliJ IDEA ,外加构建工具sbt 是也。

但因历史原因,项目组成员对 Eclipse + Maven 组合更为熟悉,为了快速实现项目原型,不增加不确定因素带来的风险,搭建一套 Eclipse + Maven + Scala-IDE 的开发环境。

基本原则是,必须完全满足但不限于以下几点内容:

  • 方便重构,方便调试,支持热部署。
  • 可直接使用已有maven的本地和私服仓库。
  • 可以无束缚的只用自己熟悉的语言编写代码。
  • 可以快速混合编译scala+java代码,包括交叉引用的文件。

如果你有洁癖,可以自己下载 Eclipse ,然后安装各种插件。但是可能会遇到插件依赖包版本冲突之类的问题,为了速度,我直接下载官方打包好的 Scala-IDE ,有各种平台可供选择。

使用 Git 管理项目源代码,需要安装 EGit 插件,Eclipse插件更新地址 EGit Updates 。

假设项目名称为 feeling ,使用 JDK 1.7,Servlet 3.0,最终目录结构如下。

.
├── .settings #eclipse工程目录
├── .classpath #eclipse classpath文件
├── .project #eclipse project文件
├── src #源代码
| ├── main #源代码主目录
| | ├── java #java代码
| | ├── scala #scala代码
| | ├── resources #资源文件
| | └── webapp #web主目录
| | ├── WEB-INF #WEB-INF目录
| | | └── web.xml #web.xml文件
| | └── index.jsp #主页面
| └── test #测试代码
| ├── java #java测试代码
| ├── scala #scala测试代码
| └── resources #测试资源文件
├── .gitignore #git忽略配置
├── target #编译输出目录
├── README.md #markdown格式的说明文件
└── pom.xml #maven的pom文件

pom.xml文件

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>feeling</groupId>
<artifactId>feeling</artifactId>
<version>0.0.1</version>
<packaging>war</packaging> <!-- <name>${project.artifactId}</name> -->
<name>feeling</name>
<description>our wonderfully feeling application</description>
<url>http://feeling.com</url>
<inceptionYear>2014</inceptionYear> <organization>
<name>feeling</name>
<url>http://feeling.com</url>
</organization> <licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses> <developers>
<developer>
<id>bruce</id>
<name>bruce sha</name>
<url>http://bruce-sha.github.io</url>
<email>bu.ru@qq.com</email>
</developer>
</developers> <scm>
<connection>http://17.20.13.23/scm/git/feeling</connection>
<developerConnection>http://17.20.13.23/scm/git/feeling</developerConnection>
<url>http://17.20.13.23</url>
</scm> <properties>
<scala.version>2.10.3</scala.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<encoding>UTF-8</encoding>
</properties> <!-- 个性化开发 -->
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.param>this is dev</build.param>
</properties>
</profile>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<build.param>this is relase</build.param>
</properties>
</profile>
</profiles> <dependencies> <!-- google -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency> <!-- servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<!-- <version>2.5</version> -->
<version>3.0.1</version>
<scope>provided</scope>
</dependency> <!-- <dependency> -->
<!-- <groupId>javax.servlet</groupId> -->
<!-- <artifactId>jsp-api</artifactId> -->
<!-- <version>2.0</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> --> <!-- scala -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency> <!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency> <!-- 其他包不再一一描述 -->
<!-- log -->
<!-- json -->
<!-- mongodb -->
<!-- quartz --> </dependencies> <build>
<finalName>feeling</finalName> <!-- 必须要,资源文件中占位符被profile替换的关键配置 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources> <!-- 必须干掉,否则不编译src/main/java下的代码 -->
<!-- <sourceDirectory>src/main/scala</sourceDirectory> -->
<!-- <testSourceDirectory>src/test/scala</testSourceDirectory> -->
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<!-- 必须要,否则不能混合编译交叉引用文件 -->
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<useFile>false</useFile>
<disableXmlReport>true</disableXmlReport>
<!-- If you have classpath issue like NoDefClassError,... -->
<!-- useManifestOnlyJar>false</useManifestOnlyJar -->
<includes>
<include>**/*Test.*</include>
<include>**/*Suite.*</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!-- 移除web.xml的依赖,Servlet 3.0可以不要web.xml文件 -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin> <!-- jetty6,不支持servlet3 -->
<!-- <plugin> -->
<!-- <groupId>org.mortbay.jetty</groupId> -->
<!-- <artifactId>maven-jetty-plugin</artifactId> -->
<!-- <version>6.1.26</version> -->
<!-- <configuration> -->
<!-- <scanIntervalSeconds>10</scanIntervalSeconds> -->
<!-- <stopKey>foo</stopKey> -->
<!-- <stopPort>9999</stopPort> -->
<!-- </configuration> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <id>start-jetty</id> -->
<!-- <phase>pre-integration-test</phase> -->
<!-- <goals> -->
<!-- <goal>run</goal> -->
<!-- </goals> -->
<!-- <configuration> -->
<!-- <scanIntervalSeconds>0</scanIntervalSeconds> -->
<!-- <daemon>true</daemon> -->
<!-- </configuration> -->
<!-- </execution> -->
<!-- <execution> -->
<!-- <id>stop-jetty</id> -->
<!-- <phase>post-integration-test</phase> -->
<!-- <goals> -->
<!-- <goal>stop</goal> -->
<!-- </goals> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- </plugin> --> <!-- tomcat7:run 注意tomcat:run跑的是6,不支持servlet3 -->
<plugin>
<!-- http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin -->
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<port>80</port>
</configuration>
</plugin> <!-- jetty:run -->
<plugin>
<!-- http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin -->
<groupId>org.mortbay.jetty</groupId>
<!-- <artifactId>maven-jetty-plugin</artifactId> 这是jetty6 不支持servlet3 -->
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.13.v20130916</version>
<configuration>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
<scanIntervalSeconds>0</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>80</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
</configuration>
</plugin> </plugins>
</build>
</project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- <web-app -->
<!-- xmlns="http://java.sun.com/xml/ns/javaee" -->
<!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" -->
<!-- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" -->
<!-- version="2.5" -->
<!-- > -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0"> <display-name>feeling</display-name> <!-- <servlet> -->
<!-- <servlet-name>feeling</servlet-name> -->
<!-- <servlet-class>feelings.service.FeelingService</servlet-class> -->
<!-- </servlet> --> <!-- <servlet-mapping> -->
<!-- <servlet-name>feeling</servlet-name> -->
<!-- <url-pattern>/feeling</url-pattern> -->
<!-- </servlet-mapping> --> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> </web-app>

.project文件:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>feeling</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

.classpath文件:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/scala">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/scala">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

搭建eclipse+maven+scala-ide的scala web开发环境的更多相关文章

  1. Spring+Maven+Dubbo+MyBatis+Linner+Handlebars—Web开发环境搭建

    本文主要分三部分,分别是:后台核心业务逻辑.桥梁辅助控制和前台显示页面. 本Web开发环境综合了多种工具,包括Maven包管理与编译工具.Dubbo分布式服务框架.MyBatis数据持久化工具.Lin ...

  2. 搭建Eclipse、Resin Web开发环境

    搭建Eclipse.Resin Web开发环境 一.当然是安装java开发环境 参看: Java环境的搭建 http://www.cnblogs.com/ghj1976/archive/2010/04 ...

  3. 使用Eclipse+Maven+Jetty构建Java Web开发环境(几个教程综合集成2014发行)

    工作需要使用Jetty由于web集装箱,得知Eclipse+Maven+Jetty该组合是非常好的,因此,要在网上找了很多教程,但不写或多或少特定的或过时的内容而导致最终的配置失败,易于配置为未来的同 ...

  4. 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(二)

    前言:在使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)中已经介绍了如何对web基础环境进行搭建,这里主要演示,如何对spring环境进行搭建,然后 ...

  5. 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)

    前言:原来一直使用MyEclipse,换工作后,新公司使用IDEA,初识IDEA发现,哇,它的快捷键可真多啊,但是一路用下来,觉得非常的好用,特别是利用Maven管理,那简直叫一个爽.当然笔者在使用过 ...

  6. Java Web 开发环境快速搭建

    Java Web 开发环境快速搭建 在因某种原因更换开发设备后,可依据此文快速搭建开发环境,恢复工作环境. Java开发环境: Windows 10 (64-bit) Oralce JDK Eclip ...

  7. Web开发环境搭建 Eclipse-Java EE 篇

    Web开发环境搭建 Eclipse-Java EE 篇 [原创内容,转载注名出处] 1. 下载和安装 1.1 下载JDK 在Java官方网站下载最新版本的 Java SE:  http://www.o ...

  8. 【转载】Maven+druid+MyBatis+Spring+Oracle+Dubbo开发环境搭建

    原地址:http://blog.csdn.net/wp1603710463/article/details/48247817#t16 Maven+druid+MyBatis+spring+Oracle ...

  9. 记录一下Web开发环境搭建 Eclipse-Java EE 篇

    转自https://www.cnblogs.com/yangyxd/articles/5615965.html Web开发环境搭建 Eclipse-Java EE 篇 [原创内容,转载注名出处] 1. ...

  10. Spring.DM web开发环境搭建

    作为一个初学者来说,搭建好Spring.DM 的web开发环境还是有些麻烦的.我就遇到了N多麻烦,走了很多弯路.本文介绍了2种比较简单的搭建Spring.DM OSGi web开发环境的搭建.   第 ...

随机推荐

  1. Docker系列(八)Kubernetes介绍

    Kubernetes组件功能图   各组件说明: 节点 节点在Kubernetes由虚拟机或者实体机表示,常称为Minion,即从属主机.当一个节点加入到Kubernetes系统中时,它将会创建一个数 ...

  2. Linux Shell 数学运算

    Linux Shell 数学运算 在Linux中直接使用数学运算符进行数学运算往往得不到我们想要的计算结果.要在Shell中进行数学运算,我们需要借助点小手段.目前,Linux Shell中进行数学运 ...

  3. HDU-4605 Magic Ball Game 树状数组+离散+dfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4605 题意:给一颗树,每个节点有个权值w[u],每个节点只有两个儿子或者没有儿子,从根节点放下一个小球 ...

  4. ubuntu源码安装R语言

    下载后解压完,进入开始配置: ./configure --enable-R-shlib 报错: configure: error: con--with-readline=yes (default) a ...

  5. 浅析作用域链–JS基础核心之一

    JS中的作用域,大家都知道的,分为全局作用域和局部作用域,没有块级作用域,听起来其实很简单的,可是作用域是否能够有深入的了解,对于JS代码逻辑的编写成功率,BUG的解决能力,以及是否能写出更优秀的代码 ...

  6. SQLServer2005数据导入Mysql到详细教程

    如果转载请注明转载地址,谢谢. SQL SERVER数据导入MYSQL目录 1.Navicat for MySQL 版本10.0.9 2.创建目标数据库 3.创建正确的SQL SERVER数据库ODB ...

  7. 自定义滚动条CSS样式

    首先,给个默认css,清除掉以前的样式,给默认背景 .scrollbar { margin-left: 30px; float: left; height: 300px; width: 65px; b ...

  8. cocos2d-x 添加纹理自动回收机制

    转自:http://www.cnblogs.com/lancidie/archive/2013/04/13/3019375.html 1.不是一个完整的模块,所以不提供完整代码,只提供思路和核心代码. ...

  9. cocos2d-x 纹理深入研究

    转自:http://blog.csdn.net/qq51931373/article/details/9152227 1.纹理控制. 看此代码: CCSprite *pSprite = CCSprit ...

  10. 【转】SQL语句中的正则表达示

    正则表达式作用是匹配方本,将一个模式(正则表达式)与一个文本串进行比较. MySQL用WHERE子句对正则表达式提供了初步的支持,允许你指定用正则表达式过滤SELECT检索出的数据. MySQL仅支持 ...