修改ivy类路径入口
Modify ivy classpath entry
下图中,我要
- Ivy 设置路径不包括 ${ivyproject_loc}
- 属性 不包含的文件 ${project_loc}
这是我现在拥有的。我在想删除常春藤库并按照我想要的方式添加它可能更容易。我知道如何添加,但删除的最佳方法是什么?
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);
}
}
}
}
}
有了项目,您可以获得所有class路径条目。我经历并排除了常春藤条目。然后我用正确的 class 路径和 属性 文件重新添加它们。现在,路径不包括 ${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 设置路径不包括 ${ivyproject_loc}
- 属性 不包含的文件 ${project_loc}
这是我现在拥有的。我在想删除常春藤库并按照我想要的方式添加它可能更容易。我知道如何添加,但删除的最佳方法是什么?
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);
}
}
}
}
}
有了项目,您可以获得所有class路径条目。我经历并排除了常春藤条目。然后我用正确的 class 路径和 属性 文件重新添加它们。现在,路径不包括 ${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);
}
}