gpt4 book ai didi

IntelliJ中带有 Play Framework 的Scala未使用的导入语句

转载 作者:行者123 更新时间:2023-12-04 19:10:03 27 4
gpt4 key购买 nike

我正在尝试学习 Scala 和 Play 框架。我选择了 IntelliJ Idea 作为ide。问题是
编辑器对像这样的进口发出警告; “未使用的导入语句”

import play.api._
import play.api.mvc._

还要对像这样的声明发出警告; “无法解析符号 Controller ”
object Login extends Controller

如何删除警告?

我遵循的步骤;

使用 play 命令创建模板创意项目;

将 Scala 编译器和库添加到外部库中。

IntelliJ Idea 版本:12.1 社区版

最佳答案

我是这样做的(我使用的是 Play!2.1.0):

C:\dev>play new community
_ _
_ __ | | __ _ _ _| |
| '_ \| |/ _' | || |_|
| __/|_|\____|\__ (_)
|_| |__/

play! 2.1.0 (using Java 1.7.0_15 and Scala 2.10.0), http://www.playframework.org

The new application will be created in C:\dev\community

What is the application name? [community]
>

Which template do you want to use for this new application?

1 - Create a simple Scala application
2 - Create a simple Java application

> 1
OK, application community is created.

Have fun!


C:\dev>cd community

C:\dev\community>play idea
[info] Loading project definition from C:\dev\community\project
[info] Set current project to community (in build file:/C:/dev/community/)
[info] Trying to create an Idea module community
[info] Updating {file:/C:/dev/community/}community...
[info] Done updating.
[info] Excluding folder target
[info] Created C:\dev\community/.idea/IdeaProject.iml
[info] Created C:\dev\community\.idea
[info] Excluding folder C:\dev\community\target\scala-2.10\cache
[info] Excluding folder C:\dev\community\target\resolution-cache
[info] Excluding folder C:\dev\community\target\streams
(commons-codec_commons-codec_1.6_test,List(commons-codec_commons-codec_1.3))
(org.apache.httpcomponents_httpcore_4.1.3_test,List(org.apache.httpcomponents_httpcore_4.0.1))
(org.apache.httpcomponents_httpclient_4.1.2_test,List(org.apache.httpcomponents_httpclient_4.0.1))
[info] Created C:\dev\community\.idea_modules/community.iml
[info] Created C:\dev\community\.idea_modules/community-build.iml

C:\dev\community>play compile
[info] Loading project definition from C:\dev\community\project
[info] Set current project to community (in build file:/C:/dev/community/)
[info] Compiling 5 Scala sources and 1 Java source to C:\dev\community\target\scala-2.10\classes...

enter image description here
Unused import statement是因为该包中没有使用任何类。通过优化导入可以安全地删除此行:Ctrl + Alt + o。

在这种情况下,我根本没有添加任何 Scala 库。我只是从命令行编译。

关于IntelliJ中带有 Play Framework 的Scala未使用的导入语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15920558/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com