简体   繁体   English

NetBeans + Scala + Maven

[英]NetBeans + Scala + Maven

I am new to Scala and relatively new to Java.我是 Scala 的新手,对 Java 也比较陌生。 I can't seem to get dialed into using an IDE with Scala.我似乎无法通过 Scala 使用 IDE。 I'm using a plain text editor and using sbt, which has worked great.我正在使用纯文本编辑器和 sbt,效果很好。 But I'd like to have code hints, and let the IDE help me resolve classes by searching for them in maven.但我想要代码提示,让 IDE 通过在 maven 中搜索来帮助我解析类。

I have the Scala plugin for NetBeans working, but it uses ant.我有用于 NetBeans 的 Scala 插件,但它使用 ant。 Code hints work, but it doesn't resolve classes for me like it does using java/maven.代码提示有效,但它不像使用 java/maven 那样为我解析类。

Is there a way to use NetBeans with Scala using Maven or SBT?有没有办法使用 Maven 或 SBT 将 NetBeans 与 Scala 一起使用?

I am not a NetBeans user but I wanted to test it with a maven setup and for me it worked well with the following pom file.我不是 NetBeans 用户,但我想使用 maven 设置对其进行测试,对我而言,它与以下 pom 文件配合良好。

It uses ScalaTest for the unit tests.它使用ScalaTest进行单元测试。

I just loaded this project by choosing Open project... and pointed to the pom file.我刚刚通过选择Open project...加载了这个项目,并指向了 pom 文件。

<?xml version="1.0" encoding="UTF-8"?>
<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.stackoverflow.Q13337089</groupId>
    <artifactId>scala</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>${project.artifactId}-${project.version}</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <scala.version>2.9.2</scala.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.9.2</artifactId>
            <version>2.0.M4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
                <executions>
                    <execution>
                        <id>scala-compile</id>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                        <configuration>
                            <args>
                                <arg>-make:transitive</arg>
                                <arg>-dependencyfile</arg>
                                <arg>${project.build.directory}/.scala_dependencies</arg>
                            </args>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7.2</version>
                <executions>
                    <execution>
                        <id>default-test</id>
                        <!-- Disable the default-test by putting it in phase none -->
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest-maven-plugin</artifactId>
                <version>1.0-M2</version>
                <configuration>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <junitxml>.</junitxml>
                    <filereports>WDF TestSuite.txt</filereports>
                    <stdout>W</stdout> <!-- Skip coloring output -->
                </configuration>
                <executions>
                    <execution>
                        <id>scala-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

https://github.com/dcaoyuan/nbscala#readme should in some incaarnation include code bridging the scala support with maven projects. https://github.com/dcaoyuan/nbscala#readme在某些方面应该包括将 scala 支持与 maven 项目桥接的代码。 the netbeans module is there in source code, not sure if it's someplace as binary. netbeans 模块在源代码中,不确定它是否是二进制文件。

This is what worked for me.这对我有用。 First install netbeans > 7.4 Second install scala plugin from netbeans plugins website follow the directions to add the plugin.首先安装 netbeans > 7.4 从netbeans 插件网站第二次安装 scala 插件,按照说明添加插件。 third create a Maven project.第三创建一个Maven项目。 New Project-> Maven -> Project From Archetype.新建项目-> Maven -> 来自原型的项目。 Then choose "scala archetype simple", then "Next" and "finish".然后选择“scala archetype simple”,然后选择“Next”和“finish”。

I've had a much better time with the Scala IDE with eclipse.我在 Scala IDE 和 Eclipse 上玩得更开心了。 That is really all you need if you are just trying to get a project going.如果您只是想让一个项目进行下去,这就是您真正需要的。

There is also an sbt plugin now for eclipse (though I've not bothered using that, as the eclipse plugin for sbt generates eclipse project files very nicely).现在还有一个用于 eclipse 的 sbt 插件(尽管我没有打扰使用它,因为 sbt 的 eclipse 插件可以很好地生成 eclipse 项目文件)。

If you want to go from an sbt build file INTO eclipse, then I can tell you that I do webapp devel with Lift (starting with an sbt build template), and I did my setup according to these instructions, which include integrating it into eclipse:如果您想从 sbt 构建文件进入 eclipse,那么我可以告诉您,我使用 Lift 进行了 webapp 开发(从 sbt 构建模板开始),并且我根据这些说明进行了设置,其中包括将其集成到 eclipse 中:

http://scala-ide.org/docs/tutorials/lift24scalaide20/index.html http://scala-ide.org/docs/tutorials/lift24scalaide20/index.html

Actually, the top-level tutorials directory has instructions for doing Play, Android devel, and others using the Scala IDE.实际上,顶级教程目录有关于使用 Scala IDE 进行 Play、Android devel 和其他操作的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM