修改 ivy 类路径条目
Posted
技术标签:
【中文标题】修改 ivy 类路径条目【英文标题】:Modify ivy classpath entry 【发布时间】:2015-08-31 03:27:26 【问题描述】:在下图中,我想要
-
Ivy 设置路径不包括 $ivyproject_loc
不包括 $project_loc 的属性文件
这就是我现在所拥有的。我在想删除 ivy 库并按照我想要的方式添加它可能会更容易。我知道如何添加,但最好的删除方法是什么?
protected void changeIvyClasspath(IProject project) throws CoreException
if(project.hasNature(JavaCore.NATURE_ID))
IJavaProject jproject = JavaCore.create(project);
IClasspathEntry[] entries = jproject.getRawClasspath();
for (IClasspathEntry entry : entries)
if(entry.toString().contains("org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER"))
if(entry.toString().contains("project_loc") || entry.toString().contains("ivyproject_loc"))
//how to remove entry?
addIvyToClasspath();
我尝试过的其他方法是修改现有设置,但没有奏效。
这是尝试这样做的代码:
protected void changeIvyClasspath(IProject project) throws CoreException
if(project.hasNature(JavaCore.NATURE_ID))
IJavaProject jproject = JavaCore.create(project);
IClasspathEntry[] entries = jproject.getRawClasspath();
for (IClasspathEntry entry : entries)
if(entry.toString().contains("org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER"))
if(entry.toString().contains("project_loc") || entry.toString().contains("ivyproject_loc"))
IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(entry.getPath(), jproject);
IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(jproject, "ivy.xml", true);
SettingsSetup ss = conf.getIvySettingsSetup();
List<String> props = new ArrayList<String>();
props.add("project.properties");
props.add(".properties/eclipse.properties");
ss.setPropertyFiles(props);
conf.setIvySettingsSetup(ss);
ss.setIvySettingsPath(".properties/ivysettings.xml");
ivycp.setConf(conf);
ivycp.launchResolve(false, null);
【问题讨论】:
【参考方案1】:通过该项目,您可以获得所有类路径条目。我经历并排除了常春藤条目。然后我用正确的类路径和属性文件重新添加了它们。现在,路径不包括 $ivyproject_loc 和 $project_loc。
代码如下:
protected void changeIvyClasspath(IProject project, IProgressMonitor monitor) throws CoreException
if(project.hasNature(JavaCore.NATURE_ID))
IJavaProject jproject = JavaCore.create(project);
List<IClasspathEntry> iClasspathEntryList = new ArrayList<IClasspathEntry>();
IClasspathEntry[] entries = jproject.getRawClasspath();
for (IClasspathEntry entry : entries)
//exclude ivy.xml entries
if (!entry.getPath().toString().contains("ivy.xml"))
iClasspathEntryList.add(entry);
//Add the ivy entries with the correct class path
addIvyToClasspath(new String[] "compile", "runtime" , true, iClasspathEntryList, project, jproject, monitor);
addIvyToClasspath(new String[] "provided", "test" , false, iClasspathEntryList, project, jproject, monitor);
entries = iClasspathEntryList.toArray(new IClasspathEntry[iClasspathEntryList.size()]);
jproject.setRawClasspath(entries, jproject.getOutputLocation(), null);
【讨论】:
以上是关于修改 ivy 类路径条目的主要内容,如果未能解决你的问题,请参考以下文章
无法从 eclipse 项目构建路径中的 apache ivy 依赖项导入类