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

Jig*_*hah 31 eclipse netbeans

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

小智 6

答案是肯定的.您可以在Netbeans中使用eclipse代码格式化程序,并享受使用Netbeans.你需要从适合你的Netbeans版本的下面位置下载eclipse代码格式化程序插件,导入你现有的eclipse代码格式化程序并准备好去

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


Ing*_*her 5

AFAIK无法将Eclipse格式设置首选项导入NetBeans.但是如果你使用Maven,你可以使用Maven2 Java Formatter Plugin,它使用Eclipse JDT功能来格式化源文件,并与Maven项目很好地集成.有关当前版本0.3.1的用法,请参见此处.

这是一个使用formatter的简单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>
Run Code Online (Sandbox Code Playgroud)

编辑:

一种不同的方法是从命令行调用Eclipse代码格式化,(但需要更长的时间,并且不很好地集成到Maven的生命周期),如所描述这里.你可以像这样格式化源文件:

/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
Run Code Online (Sandbox Code Playgroud)

(另请参阅此页面,作者将其放入一个小脚本中)

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


Bla*_*lan -1

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