【发布时间】:2016-02-14 03:40:59
【问题描述】:
我正在尝试使用 maven 资源过滤来替换 java 类中的文本。 此刻,我只是部分成功,即我有一个 java 类在两个地方有相同的占位符。运行 maven install,它会正确替换 java 类中的那个,而不是 java 类注释中声明的那个。
下面是我课堂的相关部分:
@WebServiceClient(name = "Support", targetNamespace = "http://tempuri.org/", wsdlLocation = "${java.wsdlLocation}" )
public class Support extends Service {
private final static URL SUPPORT_WSDL_LOCATION;
private final static WebServiceException SUPPORT_EXCEPTION;
private final static QName SUPPORT_QNAME = new Name("http://tempuri.org/", "Support");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("${java.wsdlLocation}");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
SUPPORT_WSDL_LOCATION = url;
SUPPORT_EXCEPTION = e;
}
从 pom 中,我有:
<resources>
<!-- Filter Java files -->
<resource>
<filtering>true</filtering>
<directory>src/main/java</directory>
<targetPath>../filtered-sources/java</targetPath>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
<!-- change default source directory to filtered-sources/java -->
<sourceDirectory>target/filtered-sources/java</sourceDirectory>
我做错了吗?不应该进行资源过滤,进行某种盲文替换,忽略它是否是java类吗? 资源过滤有什么限制吗?
【问题讨论】:
-
Here you can see 如何使用 templating-maven-plugin 来完成您喜欢的工作。
-
@khmarbaise,是否可以不使用特定的 java-template 包,而只指向特定的类或子包?抱歉,将它作为模板分开并不“听起来”好,因为作为模板不是此文件的目的。
-
java-template不是一个包,它只是一个文件夹,用于定位那些应该被过滤的类... -
@khmarbaise,我理解,对我来说有点相同,如果我使用文件夹,我需要将其作为文件而不是代码来维护......它不完全适合我的目的......无论如何,我设法让它工作,正如你在我的回答中看到的那样。谢谢
标签: java maven resources filtering