![](/img/trans.png)
[英]How to turn off the Eclipse code formatter for certain sections of Java code?
[英]How to turn off the Eclipse code formatter for certains sections of maven pom.xml
我想告訴 Eclipse 不要格式化pom.xml
屬性。
在我的示例中,我將一個長的 proxyString 參數附加到 Maven 發布插件中:
</build>
</plugins>
(...)
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.2</version>
<!-- in case of error while release prepare or dryRun release :
check proxyString should be on one line (withour CR) -->
<configuration>
<arguments>${proxyString}</arguments>
</configuration>
</plugin>
</plugins>
</build>
當我重新格式化pom.xml
,Eclipse 將一些回車附加到該定義:
<profile>
<id>proxy</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<proxyString>-Djava.net.useSystemProxies=true -Dhttp.proxyHost=myProxy -Dhttp.proxyPort=3128 -Dhttps.proxyHost=myProxy -Dhttps.proxyPort=3128</proxyString>
</properties>
</profile>
這導致了發布生命周期的中斷:
No goals have been specified for this build. You must specify a valid lifecycle phase
是否存在告訴 Eclipse 不格式化 pom.xml 的一部分的方法? (或者也許有更好的方法將代理設置轉發到 maven 發布插件)。
您可以選擇要格式化的 pom 的一部分,然后按
CTRL + SHIFT + F
當您在不選擇的情況下按 'CTRL + SHIFT + F' 時,它將格式化整個文件。
選擇將僅格式化選定的部分。
不幸的是,似乎沒有辦法為代碼的某些部分禁用 XML 格式化程序(因為 Java 代碼是可能的)。
但是,您可以增加 XML 格式化程序遵循的最大行長度:
窗口 -> 首選項 -> XML 文件 -> 編輯器
將“線寬”設置為您想要的任何值。 我已將我的設置為“999”。 現在它不會破壞太長的行。 但當然,現在我必須讓這些行足夠短,以便它保持可讀性。
我使用了一個 CDATA 部分,其中包含了我想保持原樣的文本(防止格式化)。 例如:
<additionalJvmArgs><![CDATA[-Djavax.net.debug=none -Djavax.net.ssl.trustStore=${project.basedir}/../certs/my.truststore -Djavax.net.ssl.trustStorePassword=XXXXX]]></additionalJvmArgs>
然后在Window -> Preferences -> XML -> XML Files -> Editor
我選擇了Preserve whitespace in tags with PCDATA content 。
這對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.