• <bdo id='N75vJ'></bdo><ul id='N75vJ'></ul>
    <i id='N75vJ'><tr id='N75vJ'><dt id='N75vJ'><q id='N75vJ'><span id='N75vJ'><b id='N75vJ'><form id='N75vJ'><ins id='N75vJ'></ins><ul id='N75vJ'></ul><sub id='N75vJ'></sub></form><legend id='N75vJ'></legend><bdo id='N75vJ'><pre id='N75vJ'><center id='N75vJ'></center></pre></bdo></b><th id='N75vJ'></th></span></q></dt></tr></i><div id='N75vJ'><tfoot id='N75vJ'></tfoot><dl id='N75vJ'><fieldset id='N75vJ'></fieldset></dl></div>

  • <tfoot id='N75vJ'></tfoot>

    <small id='N75vJ'></small><noframes id='N75vJ'>

    <legend id='N75vJ'><style id='N75vJ'><dir id='N75vJ'><q id='N75vJ'></q></dir></style></legend>

      1. 如何将文件夹作为库添加到 java 构建路径,其中包含多个 jar 或条目?

        How to add a folder to java build path as library, having multiple jars or entries in it?(如何将文件夹作为库添加到 java 构建路径,其中包含多个 jar 或条目?)
            <tbody id='PNhD1'></tbody>

            <bdo id='PNhD1'></bdo><ul id='PNhD1'></ul>
              <i id='PNhD1'><tr id='PNhD1'><dt id='PNhD1'><q id='PNhD1'><span id='PNhD1'><b id='PNhD1'><form id='PNhD1'><ins id='PNhD1'></ins><ul id='PNhD1'></ul><sub id='PNhD1'></sub></form><legend id='PNhD1'></legend><bdo id='PNhD1'><pre id='PNhD1'><center id='PNhD1'></center></pre></bdo></b><th id='PNhD1'></th></span></q></dt></tr></i><div id='PNhD1'><tfoot id='PNhD1'></tfoot><dl id='PNhD1'><fieldset id='PNhD1'></fieldset></dl></div>
              1. <small id='PNhD1'></small><noframes id='PNhD1'>

                1. <tfoot id='PNhD1'></tfoot>

                2. <legend id='PNhD1'><style id='PNhD1'><dir id='PNhD1'><q id='PNhD1'></q></dir></style></legend>
                  本文介绍了如何将文件夹作为库添加到 java 构建路径,其中包含多个 jar 或条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  首先我要非常感谢有钱的卖家"解决了我关于以编程方式更改 eclipse java 构建路径中的输入顺序的查询.

                  First I want to say lots of thanks to "Rich seller" to solving my query for changing the entry order in eclipse java build path programatically.

                  我想将我的库文件夹添加到其中包含多个 jar 的 java 构建路径.它应该表现得像一个类路径容器.我尝试使用 IClasspathContainer 但未能实现.

                  I want to add my Library folder to java build path which has several jars in it. It should behave like a classpath container. I tried with IClasspathContainer but failed to implement.

                  请帮帮我....

                  提前致谢.

                  YUVRAJ.

                  推荐答案

                  你应该通过实现 org.eclipse.jdt.core.classpath.ContainerInitializerextension 点.例如 org.eclipse.jdt.junit 插件在其 plugin.xml 中定义了以下内容

                  You should define a new ClasspathContainer by implementing the org.eclipse.jdt.core.classpath.ContainerInitializerextension point. For example the org.eclipse.jdt.junit plugin defines the following in its 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 类路径容器.

                  The referenced JUnitContainerInitializer creates and initialises the two JUnit classpath containers.

                  按照这种方法,您可以实现文件夹容器".有一个 DeveloperWorks 文章,展示了如何执行此操作(您需要注册才能查看文章).

                  Following this approach you can implement a "folder container". There is a DeveloperWorks article that shows how to do this (you'll need to register to view the article).

                  更新:可以在不注册扩展点的情况下定义容器,但您必须注意,如果文件夹的内容发生更改,您将无法访问生命周期方法来刷新容器.最好通过扩展点来做.

                  Update: It is possible to define a container without registering the extension point, but you have to be aware that you'll not have access to lifecycle methods to refresh the container if the contents of the folder change. It is much better to do it via the extension point.

                  下面的示例会将项目的lib"文件夹添加为自定义容器,并将在该文件夹中找到的任何 jar 文件添加为容器中的条目.它不管理源关联.

                  The example below will add the "lib" folder of a project as a custom container, and add any jar files found in the folder as entries within the container. It does not manage source associations .

                  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());
                  }
                  

                  这篇关于如何将文件夹作为库添加到 java 构建路径,其中包含多个 jar 或条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bytecode features not available in the Java language(Java 语言中不可用的字节码功能)
                  How can I add a Javaagent to a JVM without stopping the JVM?(如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?)
                  Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )(无法在 32 位 JVM 上加载 64 位 SWT 库(替换 SWT 文件))
                  Maximum number of parameters in Java method declaration(Java 方法声明中的最大参数个数)
                  Java verbose class loading(Java 详细类加载)
                  Where can I find default -Xss (stack size) value for Oracle JVM?(在哪里可以找到 Oracle JVM 的默认 -Xss(堆栈大小)值?)

                  <small id='miD7U'></small><noframes id='miD7U'>

                  <i id='miD7U'><tr id='miD7U'><dt id='miD7U'><q id='miD7U'><span id='miD7U'><b id='miD7U'><form id='miD7U'><ins id='miD7U'></ins><ul id='miD7U'></ul><sub id='miD7U'></sub></form><legend id='miD7U'></legend><bdo id='miD7U'><pre id='miD7U'><center id='miD7U'></center></pre></bdo></b><th id='miD7U'></th></span></q></dt></tr></i><div id='miD7U'><tfoot id='miD7U'></tfoot><dl id='miD7U'><fieldset id='miD7U'></fieldset></dl></div>
                    <tbody id='miD7U'></tbody>

                      <tfoot id='miD7U'></tfoot>

                        • <bdo id='miD7U'></bdo><ul id='miD7U'></ul>
                        • <legend id='miD7U'><style id='miD7U'><dir id='miD7U'><q id='miD7U'></q></dir></style></legend>