jenkins 插件解析xml文件

songcser 2013-04-23 06:01:00
在开发jenkins插件时,需要解析XML文件,使用的XStream的序列化和反序列化,在使用反序列化时,出现错误如下:com.thoughtworks.xstream.mapper.CannotResolveClassException: com.prolambda.pdm.PDMplugin.PDMProject : com.prolambda.pdm.PDMplugin.PDMProject

其中:反序列化过程是:
static{
xStream = new XStream(new DomDriver());
//xStream.processAnnotations(Project.class);
xStream.alias("project", PDMProject.class);
xStream.alias("sourceCode", SourceCode.class);
xStream.alias("dependence", Dependence.class);
}
try {InputStream in=new FileInputStream(new File("E:\\workspace\\PDMplugin\\work\\jobs\\Test1\\workspace\\P-EF.xml"));
if(in==null){
System.out.print("error");
return null;
}
PDMProject company=(PDMProject)xStream.fromXML(in);
if(company==null){
System.out.print("company error");
return null;
}
return company;
} catch (FileNotFoundException e) {
e.printStackTrace();
}

其中XML文件如下:
<project>
<id>2</id>
<name>test2</name>
<sourceCode>
<url>http://192.168.99.16:8081/svn/test</url>
<version>234</version>
</sourceCode>
<dependence>
<name>test1</name>
<version>1</version>
<repository>P-EF</repository>
<platform>win32</platform>
<configuration>Release</configuration>
<location>../</location>
</dependence>
</project>
...全文
861 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
songcser 2013-04-25
  • 打赏
  • 举报
回复
PDMProject类: package com.prolambda.pdm.PDMplugin; import java.util.ArrayList; import java.util.List; public class PDMProject { private String id; private String name; private SourceCode sourceCode = new SourceCode(); private Dependence dependence = new Dependence(); private String configFile; public PDMProject(){ super(); } public PDMProject(String id,String name,SourceCode sourceCode,Dependence dependence){ this.id = id; this.name = name; this.sourceCode = sourceCode; this.dependence = dependence; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public SourceCode getSourceCode() { return sourceCode; } public void setSourceCode(SourceCode sourceCode) { this.sourceCode = sourceCode; } public Dependence getDependence() { return dependence; } public void setDependences(Dependence dependence) { this.dependence = dependence; } public String getConfigFile() { return configFile; } public void setConfigFile(String configFile) { this.configFile = configFile; } }
cds27 2013-04-25
  • 打赏
  • 举报
回复
看一下你的PDMProject类结构,是否与XML中的内容一致。 这个我们是看不到的,要你自己看才知道。

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧