【问题标题】:Lambda expressions and Java 1.8 in IdeaUIDesignerIdeaUIDesigner 中的 Lambda 表达式和 Java 1.8
【发布时间】:2015-08-21 07:48:12
【问题描述】:

我正在尝试将 Java 1.8 与带有 Idea UI Designer 的 lambda 表达式一起使用,我在 maven 中有:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>ideauidesigner-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>javac2</goal>
            </goals>
        </execution>
    </executions>

    <configuration>
        <fork>true</fork>
        <debug>true</debug>
        <failOnError>true</failOnError>
    </configuration>
</plugin>

和依赖

<dependency>
    <groupId>com.intellij</groupId>
    <artifactId>forms_rt</artifactId>
    <version>7.0.3</version>
</dependency>

当我尝试使用 lambdas 时,它返回编译错误:

Failed to execute goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 (default) on project stockbox-chart: Execution default of goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 failed: 52264 -> [Help 1]

您对如何将 lambda 与 Idea UI Designer 一起使用有任何想法吗?

【问题讨论】:

  • 您找到解决方案了吗?
  • 不,如果我有源代码,我可以更新依赖项,也许您可​​以尝试向 JetBrains 发送问题?
  • 我刚刚发现问题在于 JetBrains 实际上并没有针对 UI 设计器的官方 maven 插件。 ideauidesigner-maven-plugin 是别人写的。如果 JetBrains 有一个官方插件就好了,但我想对它的需求不够。
  • 所以也许我们应该尝试向编写此插件的人发送消息,您与那个人有联系吗?
  • 你应该检查this的答案,因为它对我来说很好。

标签: java swing lambda java-8


【解决方案1】:

在有人能够修复插件之前,一种解决方法是配置您的 IntelliJ 设置以将 GUI 生成为源而不是二进制文件,然后手动重新生成 GUI 源之前 在您对 GUI 设计器进行更改时运行 Maven:

  1. 转到 文件 > 设置,然后将 Editor > GUI Designer > Generate GUI into: 的选择更改为 Java 源代码。。李>
  2. 每当您进行 GUI 更改时,从 IntelliJ 构建项目以(重新)生成 GUI Java 源代码(Build >> Build Project)。
  3. (可选)将生成的源代码检查到您正在使用的任何源代码控制机制中;此步骤使其他任何通过 Maven 构建您的项目的人都不必在以后从 IntelliJ 手动构建(即,他们可以仅通过 Maven 构建)。
  4. 如果您使用的是 IntelliJ 布局管理器(如 GridLayoutManager),请将 com.intellij:forms_rt:7.0.3 作为编译依赖项添加到您的 pom.xml 中(如果尚未存在)。
  5. 像往常一样运行 Maven 来构建您的项目。

【讨论】:

    【解决方案2】:

    GUI 设计器的问题在于它没有可以使用的 maven 直接插件,因为 Intellij 使用 ant 对目标 .class 文件进行后处理。您可以使用 maven ant 插件:

             <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <dependencies>
                    <dependency>
                        <groupId>com.sun</groupId>
                        <artifactId>tools</artifactId>
                        <version>1.7.0</version>
                        <scope>system</scope>
                        <systemPath>${java.home}/../lib/tools.jar</systemPath>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <configuration>
                            <tasks>
                                <path id="j2cp">
                                    <fileset dir="${project.basedir}/antlibs" includes="*.jar"/>
                                </path>
                                <path id="j2sp">
                                    <pathelement location="${project.basedir}/src/main/java"/>
                                </path>
    
                                <taskdef name="javac2" classpathref="j2cp" classname="com.intellij.ant.Javac2"/>
                                <javac2 destdir="${project.basedir}/target/classes"> 
                                    <src refid="j2sp"/>
                                </javac2>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    但是您需要将 javac2 jar 放入 /antlibs,在我的项目中我使用这些:

    • asm-5.0.3.jar
    • asm-all-7.0.1.jar
    • javac2.jar
    • jdom.jar

    您可以在 ${Intellij.home}/libs 中找到这些库

    如果你使用特定的 IDE 布局,也许你需要其他特定的 jar,如果你错过了什么,ant 插件将是特定的

    【讨论】:

      【解决方案3】:

      插件 org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1 对 Jetbrains 通过 com.intellij:javac2:7.0.3com.intellij:forms_rt:7.0.3 提供的代码有 2 个依赖项(均在 2008 年最后更新)。从那以后这些都没有直接更新,但在their own repositories 中由 Jetbrains 托管了现代等价物。

      所有要做的就是覆盖插件依赖:

      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>ideauidesigner-maven-plugin</artifactId>
          <version>1.0-beta-1</version>
          <dependencies>
              <dependency>
                  <groupId>com.jetbrains.intellij.java</groupId>
                  <artifactId>java-compiler-ant-tasks</artifactId>
                  <version>212.5284.40</version>
              </dependency>
              <dependency>
                  <groupId>com.jetbrains.intellij.java</groupId>
                  <artifactId>java-gui-forms-rt</artifactId>
                  <version>212.5284.40</version>
              </dependency>
          </dependencies>
      </plugin>
      

      并包含 Jetbrains 插件存储库

      <pluginRepositories>
          <pluginRepository>
              <id>intellij-repository</id>
              <url>https://www.jetbrains.com/intellij-repository/releases</url>
          </pluginRepository>
          <pluginRepository>
              <id>intellij-third-party</id>
              <url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
          </pluginRepository>
      </pluginRepositories>
      

      【讨论】:

        猜你喜欢
        • 2013-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-16
        • 1970-01-01
        • 2016-04-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多