2011-08-01 3 views
0

그래서 ... 템플릿에서 새 Java 프로젝트와 광고 파일을 생성하는 Eclipse 용 플러그인을 만들었지 만/src 디렉토리의 코드 라이브러리 탭에 jar 파일을 추가해야하기 때문에 컴파일 할 수 없습니다.eclipse plugin> jar 파일을 programmaticaly에 포함하는 법

이 프로젝트는 이미 통해 자바 프로젝트입니다 :

org.eclipse.jdt.core.IJavaProject javaProject = org.eclipse.jdt.core.JavaCore.create(proj); 
      org.eclipse.jdt.core.IClasspathEntry src = JavaCore.newSourceEntry(folder.getFullPath()); 
      IClasspathEntry jre = JavaCore.newContainerEntry(new Path(
        org.eclipse.jdt.launching.JavaRuntime.JRE_CONTAINER), new IAccessRule[0], 
        new IClasspathAttribute[] { 
         JavaCore.newClasspathAttribute("owner.project.facets", "java") 
        }, false); 
      IClasspathEntry[] entries = new IClasspathEntry[] { 
        src, jre 
      }; 
      javaProject.setRawClasspath(entries, proj.getFullPath().append("bin"), new NullProgressMonitor()); 

그리고 지금, 기본적으로 내가 programmaticaly 할 필요가, 버튼을 "항아리 추가 ..."무엇을한다. enter image description here

모든 코드 조언 정확히 도움이 될 것입니다 않는 튜토리얼에 대한 링크 ... 잠시 동안이 고민이었다. 제발 일반적인 이클립스 플러그인 자습서 : 나는 지금 쯤 모두 보았 듯이에는 링크 없음 ...

Thnx 많은

답변

1

은 ... 확실하지의

 IFile file = addJar(project, "/resources/myJar.jar", MY_JAR_TARGET_PATH, monitor); //$NON-NLS-1$ 
     newcpEntries.add(JavaCore.newLibraryEntry(file.getFullPath(), null, null, false)); 
     // ..... 
addJar()이 같은 모습

:

private static IFile addJar(IProject project, String srcPath, String targetPath, IProgressMonitor monitor) { 
    URL srcURL = MyPlugin.getDefault().getBundle().getEntry(srcPath); 
    IFile file = project.getFile(targetPath); 
    InputStream is = null; 
    try { 
     is = srcURL.openStream(); 
     file.create(is, true, monitor); 
    } catch (CoreException e) {//... 
       } catch (IOException e) {//... 
       } 
    finally { 
     try { 
      if (is != null) 
       is.close(); 
     } catch (IOException ignored) {} 
    } 
    return file; 
} 
+0

중요한 (중요한) 부분> JavaCore.newLibraryEntry (file.getFullPath(), null, null, false) – b0x0rz

1

당신은 이클립스 API의의를 통해 그것을 할 것입니다 방법을 잘하지만, 모든되지 않음 않는 항아리 설정 창 같은 것을 보이는 당신의 project-name/.classpath 파일에 쓸 수 있습니다 :

<?xml version="1.0" encoding="UTF-8"?> 
    <classpath> 
     <classpathentry kind="lib" path="x-jars/lucene-fast-vector-highlighter-3.0.3-patch1822.jar"/> 
     <classpathentry kind="lib" path="x-jars/lucene-highlighter-3.0.3.jar"/> 

그래서 하나 개의 옵션 셋업 코드 편집 프로젝트가 생성되면이 파일을 가질 수 있지만, 이것은 아마의 너무 많은 것 당신이 원하는 것을 해킹. 내가 그것을 어떻게 당신의 REQS이 exaclty 동일하지만, 그것이 어떤 식 으로든 도움이되기를 바랍니다 경우 여기

관련 문제