代码之家  ›  专栏  ›  技术社区  ›  Jigar Shah

我可以在NetBeans中使用或导入Eclipse格式化程序吗?

  •  31
  • Jigar Shah  · 技术社区  · 16 年前

    我们使用Eclipse已经有很长时间了。我们每个项目都有格式化程序。现在,我们中的一些人正在迁移到NetBeans。是否可以将Eclipse格式化程序迁移/同步/导入NetBeans?我尝试将Eclipse项目导入NetBeans。它不导入我们使用的格式化程序。

    8 回复  |  直到 15 年前
        1
  •  6
  •   user1556622 user1556622    12 年前

    对 . 您可以在Netbeans中使用eclipse代码格式化程序,并喜欢使用Netbeans。您需要从下面适合您的Netbeans版本的位置下载eclipse代码格式化程序插件,导入您现有的eclipse代码格式化程序并准备就绪

    http://plugins.netbeans.org/plugin/50877/eclipse-code-formatter-for-java

        2
  •  5
  •   Wolkenarchitekt    15 年前

    AFAIK没有办法将Eclipse格式化首选项导入NetBeans。 但是如果你用Maven你可以用 Maven2 Java Formatter Plugin 它使用Eclipse JDT特性格式化源文件,并与Maven项目很好地集成。有关当前版本0.3.1的用法,请参见 here .

    这很简单pom.xml文件使用格式化程序。只要放入任何Java源文件并运行 mvn java-formatter:format ,您的源代码应该使用给定的Eclipse配置文件进行格式化(其中必须提供指向您自己的配置文件的路径)。

    <?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>de.mackaz</groupId>
        <artifactId>maven.java.formatter.plugin.example</artifactId>
        <version>0.1</version>
        <packaging>jar</packaging>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
                    <artifactId>maven-java-formatter-plugin</artifactId>
                    <version>0.3.1</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>format</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                    <configFile>./example-eclipse-code-format-config.xml</configFile>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    编辑:

    另一种方法是从命令行调用Eclipse代码格式化程序(但是需要更长的时间,并且不能很好地集成到Maven生命周期中),如前所述 here . 您可以按如下方式格式化源文件:

    /opt/eclipse/eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -nosplash -config example-eclipse-code-format-config.xml src/main/java/de/mackaz/FormatMe.java
    

    (还要看一看 this page 作者把它写成了一个小剧本)

    将这些方法之一集成到NetBeans中应该很容易。或者将它们包装在一个Ant文件中并将其添加到NetBeans命令中,或者编写一个小的NetBeans插件来添加操作,例如添加到contextmenu(这非常简单,特别是与编写Eclipse插件相比)。

        3
  •  2
  •   NullPointer    15 年前

    我非常喜欢NetBeans,但在格式化方面也有同样的问题。 我找到了这个maven插件 http://mvneclipsefmt.sourceforge.net/usage.html 似乎它可以将eclipse格式化程序作为maven目标运行。但我还没试过。

        4
  •  2
  •   dolames    15 年前

    有一篇关于JBoss社区的文章似乎在讨论格式化问题,这可能会有所帮助; http://community.jboss.org/wiki/ImportFormattingRules

        5
  •  2
  •   Saeed Zarinfam    12 年前

    你可以使用“ Eclipse Code Formatter for Java “NetBeans插件它可以与NetBeans 7.3和.7.4一起使用(但有一点问题!)。

        6
  •  1
  •   Cody S    12 年前

    看起来,从Netbeans 7.3.1开始,一个非常聪明的人开发了一个Netbeans插件,它接受Eclipse Formatter XML文件。我还没有测试这个TBH,但我将在不久的将来这样做(因为我是办公室里唯一一个喜欢Netbeans而不是Eclipse的人,而且我认为我的同事正密谋因为git合并冲突而杀了我)。

    https://blogs.oracle.com/geertjan/entry/eclipse_formatter_for_netbeans_ide

        7
  •  0
  •   Meo    14 年前

    在Netbeas中使用Eclipse的格式化程序作为插件应该很容易, like it was done for IntelliJ

        8
  •  -1
  •   Blair McMillan    16 年前

    以下链接可能有帮助 http://netbeans.dzone.com/articles/importexport-code-formatting 它讨论共享设置。