我正在尝试编写一个 Maven 插件,包括 mvn 配置参数中自定义类的映射。
有谁知道等效的“Person”类会是什么样子:http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Mapping_Complex_Objects http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Mapping_Complex_Objects
<configuration>
<person>
<firstName>Jason</firstName>
<lastName>van Zyl</lastName>
</person>
</configuration>
我的自定义魔力看起来像这样:
/**
* @parameter property="person"
*/
protected Person person;
public class Person {
protected String firstName;
protected String lastName;
}
但我总是收到以下错误:
无法解析参数 person 的 mojo ...配置:无法创建类 ...$Person 的实例
有谁能够帮助我?
EDIT:
Mojo 类以 Person(包括默认构造函数、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();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)