阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

搭建Eclipse+Maven+Scala-IDE的Scala Web开发环境

474次阅读
没有评论

共计 11895 个字符,预计需要花费 30 分钟才能阅读完成。

江湖传闻,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>

使用 IntelliJ IDEA 编写 Scala 在 Spark 中运行 http://www.linuxidc.com/Linux/2015-08/122283.htm

Scala 编程完整中文版 PDF http://www.linuxidc.com/Linux/2015-08/121033.htm

快学 Scala (中文完整扫描版) PDF  http://www.linuxidc.com/Linux/2015-08/120950.htm

Ubuntu 安装 2.10.x 版本的 Scala  http://www.linuxidc.com/Linux/2015-04/116455.htm

Spark1.0.0 部署指南 http://www.linuxidc.com/Linux/2014-07/104304.htm

CentOS 6.2(64 位) 下安装 Spark0.8.0 详细记录 http://www.linuxidc.com/Linux/2014-06/102583.htm

Spark 简介及其在 Ubuntu 下的安装使用 http://www.linuxidc.com/Linux/2013-08/88606.htm

安装 Spark 集群 (在 CentOS 上) http://www.linuxidc.com/Linux/2013-08/88599.htm

Hadoop vs Spark 性能对比 http://www.linuxidc.com/Linux/2013-08/88597.htm

Spark 安装与学习 http://www.linuxidc.com/Linux/2013-08/88596.htm

Spark 并行计算模型 http://www.linuxidc.com/Linux/2012-12/76490.htm

Scala 的详细介绍 :请点这里
Scala 的下载地址 :请点这里

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-10/123824.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计11895字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19351
评论数
4
阅读量
7983376
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛 NAS 硬件 03:五盘位 +N5105+ 双网口的成品 NAS 值得入手吗 前言 大家好,我...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我用AI做了一个1978年至2019年中国大陆企业注册的查询网站

我用AI做了一个1978年至2019年中国大陆企业注册的查询网站

我用 AI 做了一个 1978 年至 2019 年中国大陆企业注册的查询网站 最近星哥在 GitHub 上偶然...
让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级 大家好,我是星哥,之前写了一篇文章 自己手撸一...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
手把手教你,购买云服务器并且安装宝塔面板

手把手教你,购买云服务器并且安装宝塔面板

手把手教你,购买云服务器并且安装宝塔面板 前言 大家好,我是星哥。星哥发现很多新手刚接触服务器时,都会被“选购...
让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级 大家好,我是星哥,之前写了一篇文章 自己手撸一...
你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你 为什么要用宝塔跑分? 宝塔跑分其实就是对 CPU、内存、磁盘、IO 做...
星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛 NAS 硬件 02:某鱼 6 张左右就可拿下 5 盘位的飞牛圣体 NAS 前言 大家好,我是星...
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸 前言 作为天天跟架构图、拓扑图死磕的...