IDEA创建helloworld

 

 

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>com.asionbest.spark</groupId>
  <artifactId>sparktrain</artifactId>
  <version>1.0-SNAPSHOT</version>
  <inceptionYear>2008</inceptionYear>
  <properties>
    <scala.version>2.11.8</scala.version>
    <spark.version>2.2.0</spark.version>
    <hadoop.version>2.6.0-cdh5.7.0</hadoop.version>
  </properties>

  <!--添加hadoop依赖时一定要添加下面这个仓库-->
  <repositories>
    <repository>
      <id>cloudera</id>
      <name>cloudera</name>
      <url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
    </repository>
  </repositories>

  <dependencies>
    <!--scala依赖-->
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>

    <!--spark依赖-->
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.11</artifactId>
      <version>${spark.version}</version>
    </dependency>

    <!--hadoop依赖-->
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-client</artifactId>
      <version>${hadoop.version}</version>
    </dependency>

  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
          <args>
            <arg>-target:jvm-1.5</arg>
          </args>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <downloadSources>true</downloadSources>
          <buildcommands>
            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
          </buildcommands>
          <additionalProjectnatures>
            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
          </additionalProjectnatures>
          <classpathContainers>
            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
          </classpathContainers>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>

创建成功后,直接运行App程序。会有报错:

Information:Module "sparkTrain" was fully rebuilt due to project configuration/dependencies changes
Information:2019/7/1 14:23 - Compilation completed with 1 error and 0 warnings in 3 s 794 ms
D:\src\sparklearn\sparkTrain\src\main\scala\com\asionbest\spark\App.scala
Error:(8, 20) not found: type Application
object App extends Application {

 

查找到stackoverflow有同样的问题,是说 Scala2.9以后就弃用了Application,所以使用2.11版本要用App替代Application,用Main替代App,需要将App文件修改成下面代码:
stackoverflow连接:https://stackoverflow.com/questions/26176509/why-does-2-11-1-fail-with-error-not-found-type-application

 

到此,idea搭建的环境完毕!

 

在使用IDEA创建一个Spring Boot项目的Hello World示例时,你可以按照以下步骤进行操作: 1. 打开IDEA并点击"Create New Project"来创建一个新项目。 2. 选择"Spring Initializr"作为项目类型,并填写项目的基本信息,如Group、Artifact、Version等。 3. 在"Dependencies"选项卡中,搜索并选择"Spring Web"依赖,这样你就可以使用Spring的Web功能。 4. 点击"Next"并选择项目的存储位置,然后点击"Finish"完成项目的创建。 在项目创建完成后,你需要在项目的初始目录下创建一个启动类。根据引用的源码,你可以创建一个名为"StudyBootDemoApplication"的类,并使用@SpringBootApplication注解标记为启动类。这个启动类中的main方法是项目的入口点,通过调用SpringApplication的run方法来启动Spring Boot应用。 接下来,你可以创建一个Controller类,如引用所示的HelloController类。在这个类中,你需要使用@RestController注解标记该类为一个Restful Controller,并使用@RequestMapping注解来映射URL路径。在此示例中,我们将路径设置为"/springboot",并在Hello方法中返回"Hello SpringBoot!"。 最后,你可以启动项目并访问"http://localhost:8080/springboot"来查看Hello World消息的输出。 需要注意的是,根据引用的配置信息,你的项目将使用内嵌的Tomcat服务器来运行,默认端口是8080。如果你希望更改端口号或进行其他配置,可以在application.properties或application.yml文件中进行相应的设置。 希望这个回答对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [【系统学习SpringBoot】SpringBoot新建HelloWorld工程(IDEA)](https://blog.csdn.net/Small_Mouse0/article/details/77800737)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值