搭建eclipse+maven+scala-ide的scala web开发环境

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.0modelVersion>
  <groupId>feelinggroupId>
  <artifactId>feelingartifactId>
  <version>0.0.1version>
  <packaging>warpackaging>

  
  <name>feelingname>
  <description>our wonderfully feeling applicationdescription>
  <url>http://feeling.comurl>
  <inceptionYear>2014inceptionYear>

  <organization>
    <name>feelingname>
    <url>http://feeling.comurl>
  organization>

  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txturl>
      <distribution>repodistribution>
    license>
  licenses>

  <developers>
    <developer>
      <id>bruceid>
      <name>bruce shaname>
      <url>http://bruce-sha.github.iourl>
      <email>[email protected]email>
    developer>
  developers>

  <scm>
  	<connection>http://17.20.13.23/scm/git/feelingconnection>
  	<developerConnection>http://17.20.13.23/scm/git/feelingdeveloperConnection>
  	<url>http://17.20.13.23url>
  scm>

  <properties>
    <scala.version>2.10.3scala.version>
    <maven.compiler.source>1.7maven.compiler.source>
    <maven.compiler.target>1.7maven.compiler.target>
    <encoding>UTF-8encoding>
  properties>

  
  <profiles>
    <profile>
      <id>devid>
      <activation>
        <activeByDefault>trueactiveByDefault>
      activation>
      <properties>
        <build.param>this is devbuild.param>
      properties>
    profile>
    <profile>
      <id>releaseid>
      <activation>
        <activeByDefault>falseactiveByDefault>
      activation>
      <properties>
        <build.param>this is relasebuild.param>
      properties>
    profile>
  profiles>

  <dependencies>

    
    <dependency>
      <groupId>com.google.guavagroupId>
      <artifactId>guavaartifactId>
      <version>15.0version>
    dependency>
    <dependency>
      <groupId>com.google.injectgroupId>
      <artifactId>guiceartifactId>
      <version>3.0version>
    dependency>

    
    <dependency>
      <groupId>javax.servletgroupId>
      <artifactId>javax.servlet-apiartifactId>
      
      <version>3.0.1version>
      <scope>providedscope>
    dependency>

    
    
    
    
    
    

    
    <dependency>
      <groupId>org.scala-langgroupId>
      <artifactId>scala-libraryartifactId>
      <version>${scala.version}version>
    dependency>

    
    <dependency>
      <groupId>junitgroupId>
      <artifactId>junitartifactId>
      <version>4.11version>
      <scope>testscope>
    dependency>

        
    
    
    
    

  dependencies>

  <build>
    <finalName>feelingfinalName>

    
    <resources>
      <resource>
        <directory>src/main/resourcesdirectory>
        <includes>
          <include>*.*include>
        includes>
        <filtering>truefiltering>
      resource>
    resources>

    
    
    
    <plugins>
      <plugin>
        
        <groupId>net.alchim31.mavengroupId>
        <artifactId>scala-maven-pluginartifactId>
        <version>3.1.6version>
        
        <executions>
          <execution>
            <id>scala-compile-firstid>
            <phase>process-resourcesphase>
            <goals>
              <goal>add-sourcegoal>
              <goal>compilegoal>
            goals>
          execution>
          <execution>
            <id>scala-test-compileid>
            <phase>process-test-resourcesphase>
            <goals>
              <goal>testCompilegoal>
            goals>
          execution>
        executions>
      plugin>
      <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-surefire-pluginartifactId>
        <version>2.13version>
        <configuration>
          <useFile>falseuseFile>
          <disableXmlReport>truedisableXmlReport>
          
          
          <includes>
            <include>**/*Test.*include>
            <include>**/*Suite.*include>
          includes>
        configuration>
      plugin>
      <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-war-pluginartifactId>
        <version>2.4version>
        <configuration>
          
          <failOnMissingWebXml>falsefailOnMissingWebXml>
        configuration>
      plugin>

      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

      
      <plugin>
        
        <groupId>org.apache.tomcat.mavengroupId>
        <artifactId>tomcat7-maven-pluginartifactId>
        <version>2.2version>
        <configuration>
          <path>/path>
          <port>80port>
        configuration>
      plugin>

      
      <plugin>
        
        <groupId>org.mortbay.jettygroupId>
        
        <artifactId>jetty-maven-pluginartifactId>
        <version>8.1.13.v20130916version>
        <configuration>
          <stopPort>9966stopPort>
          <stopKey>foostopKey>
          <scanIntervalSeconds>0scanIntervalSeconds>
          <connectors>
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
              <port>80port>
              <maxIdleTime>60000maxIdleTime>
            connector>
          connectors>
          <webAppConfig>
            <contextPath>/contextPath>
          webAppConfig>
        configuration>
      plugin>

    plugins>
  build>
project>

web.xml








<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>feelingdisplay-name>

  
  
  
  

  
  
  
  
  
  <welcome-file-list>
    <welcome-file>index.htmlwelcome-file>
    <welcome-file>index.htmwelcome-file>
    <welcome-file>index.jspwelcome-file>
    <welcome-file>default.htmlwelcome-file>
    <welcome-file>default.htmwelcome-file>
    <welcome-file>default.jspwelcome-file>
  welcome-file-list>
  
web-app>

.project文件:


<projectDescription>
  <name>feelingname>
  <comment>comment>
  <projects>
  projects>
  <buildSpec>
    <buildCommand>
      <name>org.scala-ide.sdt.core.scalabuildername>
      <arguments>
      arguments>
    buildCommand>
    <buildCommand>
      <name>org.eclipse.m2e.core.maven2Buildername>
      <arguments>
      arguments>
    buildCommand>
  buildSpec>
  <natures>
    <nature>org.scala-ide.sdt.core.scalanaturenature>
    <nature>org.eclipse.jdt.core.javanaturenature>
    <nature>org.eclipse.m2e.core.maven2Naturenature>
  natures>
projectDescription>

.classpath文件:


<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>

转载于:https://www.cnblogs.com/bluejoe/p/5115838.html

你可能感兴趣的:(搭建eclipse+maven+scala-ide的scala web开发环境)