在我的范例工程中有如下類:
import javax.persistence.*;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@Entity
public class Product extends BaseObject {
private static final long serialVersionUID = -7166739807708948462L;
private Long id;
private String code;
private String name;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(nullable=false, length=50, unique=true)
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Column(nullable=false, length=50)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((code == null) ? 0 : code.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Product other = (Product) obj;
if (code == null) {
if (other.code != null)
return false;
} else if (!code.equals(other.code))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
.append("code", this.code)
.append("name", this.name);
return sb.toString();
}
}
這個(gè)類沒有什么特別的地方,但運(yùn)行mvn appfuse:gen -Dentity=Product為它生成CRUD相關(guān)的代碼時(shí)卻如下錯(cuò)誤:
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] E:\USR\openstore\target\appfuse\generated-sources\src\test\resources\Product-sample-data.xml doesn't exist
[INFO] ------------------------------------------------------------------------
[INFO] Trace
E:\USR\openstore\target\appfuse\generated-sources\src\test\resources\Product-sample-data.xml doesn't exist
at org.apache.tools.ant.taskdefs.LoadResource.execute(LoadResource.java:142)
at org.appfuse.tool.ArtifactInstaller.installSampleData(ArtifactInstaller.java:135)
at org.appfuse.tool.ArtifactInstaller.execute(ArtifactInstaller.java:47)
at org.appfuse.mojo.exporter.AppFuseGeneratorMojo.doExecute(AppFuseGeneratorMojo.java:262)
at org.appfuse.mojo.HibernateExporterMojo.execute(HibernateExporterMojo.java:138)
at org.appfuse.mojo.exporter.AppFuseGeneratorMojo.execute(AppFuseGeneratorMojo.java:202)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:447)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:493)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:463)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:333)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:126)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:282)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
仔細(xì)查看了Product的源碼,沒有什么錯(cuò)啊......配置文件也看不出有什么問題......其它類都能正常地生成代碼,就這個(gè)類死活不行。
注意到運(yùn)行mvn appfuse:remove -Dentity=Product的過程中有如下提示:
[info] [AppFuse] Removing generated files (pattern: **/Product*.java)
[info] [AppFuse] Removing sample data for DbUnit
[info] [AppFuse] Removing Spring bean definitions
[info] [AppFuse] Removing Struts views and configuring
[info] [AppFuse] Removing generated files (pattern: **/model/*.xml)
[info] [AppFuse] Removing generated files (pattern: **/webapp/action/*.xml)
[info] [AppFuse] Removing generated files (pattern: Product*.jsp)
其中多處有Product*字樣。想到項(xiàng)目中還有另一個(gè)類ProductCategory(已經(jīng)為它生成了代碼),是不是兩個(gè)類之間有什么沖突?于是做如下嘗試:
1.備份Product.java和ProductCategory.java
2.運(yùn)行mvn appfuse:remove -Dentity=ProductCategory刪除已經(jīng)生成的ProductCategory相關(guān)的代碼
3.運(yùn)行mvn appfuse:remove -Dentity=Product刪除殘留的Product相關(guān)的代碼
4.恢復(fù)Product.java和ProductCategory.java到原目錄中
5.將類ProductCategory改名為Category,相應(yīng)地將文件ProductCategory.java改名為Category.java
6.運(yùn)行mvn appfuse:gen -Dentity=Category
7.運(yùn)行mvn appfuse:gen -Dentity=Product
以上所有的步驟均執(zhí)行成功!表明對于AppFuse的maven plugin來說,類Product和ProductCategory之間確實(shí)存在沖突。問題雖然可以繞過,但涉及的兩個(gè)類的名稱都是合法的Java類名,這不能不說是AMP的一個(gè)缺陷,我已經(jīng)在官方論壇上發(fā)了一個(gè)帖子,希望作者能盡快修復(fù)
posted on 2008-03-06 11:52
雨奏 閱讀(1016)
評論(0) 編輯 收藏