Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 以编程方式将eclipse格式化程序配置文件XML导出到.prefs中_Java_Eclipse_Code Formatting - Fatal编程技术网

Java 以编程方式将eclipse格式化程序配置文件XML导出到.prefs中

Java 以编程方式将eclipse格式化程序配置文件XML导出到.prefs中,java,eclipse,code-formatting,Java,Eclipse,Code Formatting,我的团队使用eclipse概要文件XML文件中定义的代码格式约定,该文件如下所示: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <profiles version="12"> <profile kind="CodeFormatterProfile" name="This Team's Formatting Convention" version="12"> <setting id="or

我的团队使用eclipse概要文件XML文件中定义的代码格式约定,该文件如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="This Team's Formatting Convention"  version="12">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
...
只有当
${JAVA\u FORMATTER\u CONFIG\u FILE}
是一个eclipse首选项文件,其文件名为
org.eclipse.jdt.core.prefs
且内容为:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

如何以编程方式获取
.prefs
文件,而无需从eclipse UI手动导入XML概要文件?

从eclipse Oxygen workbench

  • 导出当前首选项:文件->导出->首选项
  • 选择“Java代码样式首选项”
  • 选择名称和目标并保存(似乎必须使用.epf扩展名)
该文件将包含(除其他外)自定义fomatter配置

/instance/org.eclipse.jdt.ui/formatter_profile=_my-java-formatter
/instance/org.eclipse.jdt.ui/formatter_settings_version=13
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.formatterprofiles=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<profiles version\="13">\n<profile kind\="CodeFormatterProfile" name\="my-java-formatter" version\="13">\n...
...
输出:

org.eclipse.m2e.logback.configuration: The org.eclipse.m2e.logback.configuration bundle was activated before the state location was initialized.  Will retry after the state location is initialized.
org.eclipse.m2e.logback.configuration: Logback config file: /home/luis/eclipse-workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.8.3.20180227-2137.xml
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [bundleresource://496.fwk1538849250:1/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [bundleresource://496.fwk1538849250:2/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
org.eclipse.m2e.logback.configuration: Initializing logback
Configuration Name: eclipse-formatter.epf
Starting format job ...
Done.
首选项导出完成一次,然后您可以共享
eclipse formatter.epf
文件。
希望对您有所帮助。

使用XSLT、正则表达式或从XML中读取ID/值对并将其保存到属性文件,可以轻松地将XML文件转换为属性文件:
=>
${ID}=${value}
。或者我误解了您的问题,而不是将格式化程序配置文件XML转换为
.settings/org.eclipse.jdt.core.prefs
?我明白了。我不确定XML是否有任何特殊处理或映射到.pref值。我真的在寻找一种以编程方式实现这一点的方法。但是,假设上游XML文件从未更改,或者我不必处理多个XML,那么我想您是对的,这只能执行一次,并且.prefs或.epf文件可以共享。如果上游XML规范发生变化,那么我想我会在评论中使用霍尔格的建议。下面是以编程方式导出/导入的和。
eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -config eclipse-formatter.epf Test.java
org.eclipse.m2e.logback.configuration: The org.eclipse.m2e.logback.configuration bundle was activated before the state location was initialized.  Will retry after the state location is initialized.
org.eclipse.m2e.logback.configuration: Logback config file: /home/luis/eclipse-workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.1.8.3.20180227-2137.xml
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [bundleresource://496.fwk1538849250:1/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [bundleresource://496.fwk1538849250:2/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
org.eclipse.m2e.logback.configuration: Initializing logback
Configuration Name: eclipse-formatter.epf
Starting format job ...
Done.