1. interface來(lái)定義系統(tǒng)對(duì)外提供的服務(wù),有抽象類(lèi)來(lái)做擴(kuò)展。盡量用interface作為參數(shù)類(lèi)型。

          2. ThreadLocal類(lèi),定義了一個(gè)變量的本地副本,與原有變量隔離,作用類(lèi)似static變量,只是不共享。可用set添加變量,get去獲取變量。變量類(lèi)型不限制。

          3. Eclipse plug in開(kāi)發(fā)中可以實(shí)現(xiàn)IRuntimeClasspathProvider接口。可以提供用launch configuration去獲得unresolvedresolved classpath。開(kāi)發(fā)人員可以在resolveClasspath方法中加入自定義的classpath。實(shí)現(xiàn)類(lèi)需要注冊(cè)在extension point中。

                /**

                 *Computesandreturnsanunresolvedclasspathforthegivenlaunchconfiguration.

                 *Variableandcontainerentriesarenotresolved.

                 *

                 *@paramconfigurationlaunchconfiguration

                 *@returnunresolvedpath

                 *@exceptionCoreExceptionifunabletocomputeapath

                 */

                public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException;

               

                /**

                 *Returnstheresolvedpathcorrespondingtothegivenpath,inthecontextofthe

                 *givenlaunchconfiguration.Variableandcontainerentriesareresolved.Thereturned

                 *(resolved)pathneednothavethesamenumberofentriesasthegiven(unresolved)

                 *path.

                 *

                 *@paramentriesentriestoresolve

                 *@paramconfigurationlaunchconfigurationcontexttoresolvein

                 *@returnresolvedpath

                 *@exceptionCoreExceptionifunabletoresolveapath

                 */

                public IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration) throws CoreException;

          A provider extension is defined in plugin.xml. Following is an example definition of a runtime classpath provider extension.

           <extension point="org.eclipse.jdt.launching.classpathProviders">
             <classpathProvider 
                id="com.example.ExampleClasspathProvider"
                class="com.example.ExampleClasspathProviderImpl"
             </classpathProvider>
           </extension>

          4. plug in 開(kāi)發(fā)中可以用JavaRuntime 去得到運(yùn)行環(huán)境的信息。        
          IRuntimeClasspathProvider provider = JavaRuntime
          .getClasspathProvider(configuration);

          其中configurationILaunchConfiguration類(lèi)型的。

          4. Eclipse plug in開(kāi)發(fā)中獲取文件。兩種解決辦法:1.plug in實(shí)例中讀取文件的URL,然后用FileLocator把這個(gè)URL轉(zhuǎn)化成文件路徑;2.直接利用FileLocatorfind方法。

          方法1

                      //filepath 是需要定位的文件

                      String filepath = "/bin/resources/test.jar";

                      //instance 是當(dāng)前plug in的實(shí)例

                      URL url = instance.getBundle().getEntry(filepath);

                      String path = null;

                      try {

                            path = FileLocator.resolve(url).getPath();

                      } catch (IOException e) {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                      }

                      returnnew Path(path);

                }

          方法2

                      String filepath = "/bin/resources/test.jar";

                      URL url = FileLocator.find(instance.getBundle(),new Path(filepath),null);

                      try {

                            path = FileLocator.resolve(url).getPath();

                      } catch (IOException e) {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                      }

          5. 可以利用JarOutputStream來(lái)寫(xiě)jar包。必須為JarOutputStream 實(shí)例創(chuàng)建至少一個(gè)Entry,可以調(diào)用putNextEntry方法。

                      Manifest mf = new Manifest();

                      JarOutputStream jar = new JarOutputStream(new FileOutputStream("MainTest.jar")mf);

                      Properties properties = new Properties();

                      jar.putNextEntry(new ZipEntry("MainTest.property"));

                      properties.store(jar, "this is a test");

                      jar.close();

          6. 得到IJavaModle

                IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace()

                                        .getRoot());

                IJavaProject[] projects = model.getJavaProjects();

                IPackageFragmentRoot[] roots = projects[i]                                          .getPackageFragmentRoots();

           然后可以依次得到對(duì)應(yīng)elements


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          posts - 6, comments - 8, trackbacks - 0, articles - 1

          Copyright © 遲來(lái)的兵

          主站蜘蛛池模板: 唐河县| 北海市| 南昌县| 滨海县| 蒙阴县| 庄河市| 兴山县| 内丘县| 龙里县| 翁牛特旗| 南部县| 和静县| 胶南市| 江北区| 罗江县| 汉阴县| 甘谷县| 金乡县| 兴义市| 康乐县| 桑植县| 永福县| 邳州市| 普洱| 邛崃市| 丹东市| 阳朔县| 呼伦贝尔市| 怀宁县| 平泉县| 武胜县| 峨边| 麻城市| 藁城市| 平湖市| 桃源县| 垫江县| 赤水市| 盐池县| 腾冲县| 河津市|