我正在尝试编写一个Maven插件,包括MVN配置参数中的自定义类映射。是否有人知道同等类"人"的样子:http://maven.apache.org/guides/mini/guide-configuring-plugins.html#mapping_complex_objects
<configuration>
<person>
<firstName>Jason</firstName>
<lastName>van Zyl</lastName>
</person>
</configuration>
我的自定义Mojo看起来像:
/**
* @parameter property="person"
*/
protected Person person;
public class Person {
protected String firstName;
protected String lastName;
}
,但我总是会收到以下错误:无法解析Mojo的配置...对于参数人员:无法创建类的实例... $ Person
有人可以帮助我吗?
编辑:
Mojo类带人(包括默认构造函数,getter&setter)为内类。
public class BaseMojo extends AbstractMojo {
/**
* @parameter property="ios.person"
*/
protected Person person;
public class Person {
/**
* @parameter property="ios.firstName"
*/
protected String firstName;
/**
* @parameter property="ios.lastName"
*/
protected String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Person() {
}
}
如果使用内部类,则必须是静态的,因此可以启动它而无需首先创建外部类。如果内部类是使用外部类的私人变量创建的,但Maven只是没有这样做。
希望以下示例有助于解释为什么它不起作用...
public class ExampleClass {
public class InnerInstance {}
public static class InnerStatic {}
public static void main(String[] args) {
// look, we have to create the outer class first (maven doesn't know it has to do that)
new ExampleClass().new InnerInstance();
// look, we've made it without needing to create the outer class first
new ExampleClass.InnerStatic();
// mavens trying to do something like this at runtime which is a compile error at compile time
new ExampleClass.InnerInstance();
}
}