org.eclipse.jdt.core.classpath.ContainerInitializerextension 포인트를 구현하여 새 클래스 패스 컨테이너를 정의해야합니다. 예를 들어, org.eclipse.jdt.junit 플러그인의 plugin.xml에
<extension
point="org.eclipse.jdt.core.classpathContainerInitializer">
<classpathContainerInitializer
class="org.eclipse.jdt.internal.junit.buildpath.JUnitContainerInitializer"
id="org.eclipse.jdt.junit.JUNIT_CONTAINER">
</classpathContainerInitializer>
</extension>
참조 된 JUnitContainerInitializer가 생성에서 다음을 정의하고이 개 JUnit을 클래스 패스 컨테이너를 초기화한다.
이 방법을 따르면 "폴더 컨테이너"를 구현할 수 있습니다. 이 작업을 수행하는 방법을 보여주는 DeveloperWorks article이 있습니다 (기사를 보려면 등록해야합니다).
업데이트 : 그것은 확장 점을 회원 가입없이 컨테이너를 정의 할 수 있습니다,하지만 당신은 당신이 용기를 새로 라이프 사이클 방법에 액세스 할 수 있습니다 알고 있어야 할 경우 폴더의 내용이 변경. 확장 점을 통해 수행하는 것이 훨씬 낫습니다.
아래 예제에서는 프로젝트의 "lib"폴더를 사용자 지정 컨테이너로 추가하고 해당 폴더에있는 모든 jar 파일을 컨테이너 내의 항목으로 추가합니다. 소스 연결을 관리하지 않습니다.
final String description = "My container";
IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("foo");
//get the lib folder, TODO check if it exists!
final IFolder folder = project.getFolder("lib");
//define a unique path for the custom container
final IPath containerPath = new Path(
"my.custom.CLASSPATH_CONTAINER").append(project
.getFullPath());
IJavaProject javaProject = JavaCore.create(project);
//create a container that lists all jars in the lib folder
IClasspathContainer customContainer = new IClasspathContainer() {
public IClasspathEntry[] getClasspathEntries() {
List<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>();
try {
// add any members that are files with the jar extension
IResource[] members = folder.members();
for (IResource resource : members) {
if (IFile.class.isAssignableFrom(resource
.getClass())) {
if (resource.getName().endsWith(".jar")) {
entryList.add(JavaCore.newLibraryEntry(
new Path(resource.getFullPath()
.toOSString()), null,
new Path("/")));
}
}
}
} catch (CoreException e) {
// TODO handle the exception
e.printStackTrace();
}
// convert the list to an array and return it
IClasspathEntry[] entryArray = new IClasspathEntry[entryList
.size()];
return entryList.toArray(entryArray);
}
public String getDescription() {
return description;
}
public int getKind() {
return IClasspathEntry.CPE_CONTAINER;
}
public IPath getPath() {
return containerPath;
}
@Override
public String toString() {
return getDescription();
}
};
//register the custom container so when we add its path it is discovered
JavaCore.setClasspathContainer(containerPath,
new IJavaProject[] { javaProject },
new IClasspathContainer[] { customContainer }, null);
IClasspathEntry[] entries = javaProject.getRawClasspath();
//check if the container is already on the path
boolean hasCustomContainer = false;
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER
&& entries[i].getPath().equals(containerPath)) {
hasCustomContainer = true;
}
}
if (!hasCustomContainer) {
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
// add a new entry using the path to the container
newEntries[entries.length] = JavaCore
.newContainerEntry(customContainer.getPath());
javaProject.setRawClasspath(newEntries,
new NullProgressMonitor());
}
사실 저는 plugin.xml을 사용하지 않고 구현해야합니다. 자바 코드만으로 구현해야합니다 ..... 라이브러리 폴더 s 자바 빌드 경로의 라이브러리 탭에서 JRE 라이브러리와 같은 ICON을 가져야합니다. 라이브러리 이름을 확장하면 jar 파일이 표시됩니다. –
잘 모르겠습니다. 코드를 Eclipse 내부에 액세스 할 수 있도록 플러그인에 구현해야합니다. 그렇지 않으면 어떻게 구현합니까? –
감사합니다. Rich, 나는 내 클라이언트의 요구 사항을 얻지 못했고 이제는 plugin.xml을 사용하도록 말할 수 있습니다. 다시 한 번 감사드립니다. 계속 묻습니다. 좋은 밤. –