eclipse开发工程右键菜单例子-程序员宅基地

技术标签: ui  运维  开发工具  

打开eclipse 或者myeclipse  选中任意位置 new puginproject

输入工程名称 其他默认

 

选择向导里面的一项  plugin in with a popup menu 右边的框中 有一项

 


Extension Used
org.eclipse.ui.popupMenus 

 

这个就是他的point

 

完成后 打开 pluginx.ml 会出现9个属性设置也 depend表示工程依赖的包,点击倒数第二个 pugin。xml中可以

看到下面的内容

 

 <extension
         point="org.eclipse.ui.popupMenus">
      <objectContribution
            objectClass="org.eclipse.jdt.core.IJavaProject"
            id="menuplugin.contribution1">
         <menu
               label="lh+jar"
               path="additions"
               id="menuplugin.menu1">
            <separator
                  name="group1">
            </separator>
         </menu>
         <action
               label="ssh"
               class="lhplugin.popup.SSHAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.SSHAction">
         </action>

</extension>

 

 point="org.eclipse.ui.popupMenus" 表示是工程的右键菜单

objectClass="org.eclipse.jdt.core.IJavaProject"  表示该右键菜单仅对java工程有效

主要有以下几种值:

IJaveProject:只能在java项目单击菜单才出现。
IJavaElement:在任意Java元素上单击菜单有效。
IAdaptable:在任意处打击都有效。


<menu
               label="lh+jar"
               path="additions"
               id="menuplugin.menu1">
            <separator
                  name="group1">
            </separator>
         </menu>

表示会在右键中添加一个 名字叫lh+jar的菜单 一般id命名尽量唯一  尽量使用类名

 

<action
               label="ssh"
               class="lhplugin.popup.SSHAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.SSHAction">
         </action>

表示添加一个时间 menubarPath 表示将ssh这个菜单添加到menuplugin.menu1菜单下 并且以group1作为分隔符

class 表示 在点击ssh的时候 执行这个类中的某一个方法

 

右键菜单的类 必须实现 IObjectActionDelegate 接口

 

public void run(IAction action)

该方法就是 点击菜单的时候要执行的方法

 IStructuredSelection selection = null;

public void selectionChanged(IAction action, ISelection selection) {
  if (selection != null && selection instanceof IStructuredSelection) {
   this.selection = (IStructuredSelection) selection;
  }
 }

该方法 就是获取点击什么东西弹出的菜单

selection对象就表示选择的什么东西 可以是javaproject project 文件等

现在比如要做一个添加各种jar包的例子

 

首先转到depend属性设置也

添加

 org.eclipse.jdt.ui;

 org.eclipse.jdt.core;

 

如果对java工程使用必须用到jdt

pugin.xml中

 

 <extension
         point="org.eclipse.ui.popupMenus">
      <objectContribution
            objectClass="org.eclipse.jdt.core.IJavaProject"
            id="menuplugin.contribution1">
         <menu
               label="lh+jar"
               path="additions"
               id="menuplugin.menu1">
            <separator
                  name="group1">
            </separator>
         </menu>
         <action
               label="ssh"
               class="lhplugin.popup.SSHAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.SSHAction">
         </action>
         <action
               label="luence"
               class="lhplugin.popup.LunceneAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.lucenceAction">
         </action>
         <action
               label="cxf"
               class="lhplugin.popup.CxfAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.CxfAction">
         </action>
         <action
               label="ftpserver"
               class="lhplugin.popup.FtpServerAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.FtpServerAction">
         </action>
         <action
               label="quartz"
               class="lhplugin.popup.QuartzAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.quartzAction">
         </action>
          <action
               label="log4j"
               class="lhplugin.popup.Log4jAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.log4jAction">
         </action>
         <action
               label="ant"
               class="lhplugin.popup.AntAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.AntAction">
         </action>
          <action
               label="hsqldb"
               class="lhplugin.popup.HsqldbAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.HsqldbAction">
         </action>
         <action
               label="velocity"
               class="lhplugin.popup.VelocityAction"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.VelocityAction">
         </action>
          <action
               label="struts2"
               class="lhplugin.popup.Struts2Action"
               menubarPath="menuplugin.menu1/group1"
               enablesFor="1"
               id="menuplugin.Struts2Action">
         </action>
      </objectContribution>
   </extension>

 

 

添加一个父类 用于处理拷贝jar包的任务

 

package lhplugin.popup;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Properties;

import lhplugin.Activator;

import org.eclipse.core.internal.resources.Folder;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;

public abstract class SuperDelegate implements IObjectActionDelegate {

 public String[] getAllJar(String sign) throws IOException {
  // 通过获取jar包中的 config文件从而不去到对应的jar包的名称
  URL config = Activator.getDefault().getBundle().getEntry(
    "jarconfig.properties");
  InputStream stream = config.openStream();
  Properties p = new Properties();
  p.load(stream);
  String sshpackage = p.getProperty(sign);
  return sshpackage.split(";");
 }
 public static void createFolder(IJavaProject project, String src){
  URL proUrl = Activator.getDefault().getBundle().getEntry(src);
  IFolder folder= project.getProject().getFolder(src);
  if (!folder.exists())
   try {
    folder.create(true, true, null);
   } catch (CoreException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
 }
 public static void createFile(IJavaProject project, String[] src,
   String[] dst) {
  for (int i = 0; i < src.length; i++) {
   String pro = src[i];
   URL proUrl = Activator.getDefault().getBundle().getEntry(pro);
   IFile file = project.getProject().getFile(dst[i]);
   try {
    file.create(proUrl.openStream(), false,
      new NullProgressMonitor());
   } catch (CoreException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }

 private static boolean classPathExists(IClasspathEntry[] entrys,
   IClasspathEntry entry) {
  for (int i = 0, n = entrys.length; i < n; i++) {
   if (entrys[i].getPath().equals(entry.getPath())) {
    return true;
   }
  }
  return false;
 }

 public IJavaProject run(final String dir, final String sign) {

  final Object obj = selection.getFirstElement();
  if (obj instanceof IJavaProject) {
   final IJavaProject project = (IJavaProject) obj;
   IRunnableWithProgress process = new IRunnableWithProgress() {

    public void run(IProgressMonitor m)
      throws InvocationTargetException, InterruptedException {
     try {
      m.beginTask("开始获取源路径和对应jar包路径", 2);
      // 获取jar包中的lib目录

      // 获取到工程下面所有的classpath
      // 通过配置文件获取到对应的jar包
      String[] list = getAllJar(sign);
      m.worked(1);
      m.setTaskName("开始拷贝jar包及设置源路径");
      // 判断lib到底是在根目录下 还是web工程的webroot下面
      String libPath = "lib/";
      IFolder libFolder = project.getProject().getFolder(
        "WebRoot/WEB-INF/lib/");
      if (libFolder.exists())
       libPath = "WebRoot/WEB-INF/lib/";

      // 循环拷贝jar包 以及设置环境变量
      for (String file : list) {
       // 如何是jar包的话 就要设置环境变量
       if (file.endsWith(".jar")) {
        IClasspathEntry[] entry = project
          .readRawClasspath();

        IClasspathEntry newentry = JavaCore
          .newLibraryEntry(project.getProject()
            .getFile(libPath + file)
            .getFullPath(), null, null);
        if (!classPathExists(entry, newentry)) {
         IClasspathEntry[] ceArray = new IClasspathEntry[entry.length + 1];
         System.arraycopy(entry, 0, ceArray, 0,
           entry.length);

         IFile ctFile = project.getProject()
           .getFile(libPath + file);
         URL fileUrl = Activator.getDefault()
           .getBundle().getEntry(
             dir + "/" + file);

         IFolder folder = project.getProject()
           .getFolder(libPath);
         if (!folder.exists())
          folder.create(true, true, null);
         ctFile.create(fileUrl.openStream(), false,
           m);

         ceArray[ceArray.length - 1] = newentry;
         project.setRawClasspath(ceArray, m);

        }
        // 如果不是jar包就不管
       }
      }
      m.worked(1);
     } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } finally {
      m.done();
     }

    }

   };
   ProgressMonitorDialog d = new ProgressMonitorDialog(null);
   try {
    d.run(true, false, process);
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   return project;
  }
  return null;

 }

 IStructuredSelection selection = null;

 /**
  * @see IActionDelegate#selectionChanged(IAction, ISelection)
  */
 public void selectionChanged(IAction action, ISelection selection) {
  if (selection != null && selection instanceof IStructuredSelection) {
   this.selection = (IStructuredSelection) selection;
  }
 }

}

每一类型的jar包添加菜单对应一个action都实现该父类

添加ant的jar

package lhplugin.popup;

import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class AntAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public AntAction() {
  super();
 }
 //应该是插件jar包的相应jar包的位置
 private String dir = "lib/ant";
 private String sign="ant";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  IJavaProject project = super.run(dir, sign);
  super.createFile(project,
    new String[] { "lib/ant/build.xml" },
    new String[] { "build.xml" });
 }


}

添加cxf的jar

 

package lhplugin.popup;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class CxfAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public CxfAction() {
  super();
 }
 //应该是插件jar包的相应jar包的位置
 private String dir = "lib/cxf";
 private String sign="cxf";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  super.run(dir,sign);
 }


}

添加ftpserver的jar

 

package lhplugin.popup;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;

import lhplugin.utils.FtpGen;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class FtpServerAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public FtpServerAction() {
  super();
 }

 // 应该是插件jar包的相应jar包的位置
 private String dir = "lib/ftpserver";
 private String sign = "ftpserver";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  final IJavaProject project = run(dir, sign);
  IRunnableWithProgress process = new IRunnableWithProgress() {

   public void run(IProgressMonitor m)
     throws InvocationTargetException, InterruptedException {
    try {
     // TODO Auto-generated method stub
     m.beginTask("开始创建conf文件夹", 3);
     createFolder(project, "conf");
     m.worked(1);
     m.setTaskName("开始插件配置文件");
     createFile(project, new String[] {
       "lib/ftpserver/ftpserver.jks",
       "lib/ftpserver/users.properties" }, new String[] {
       "conf/ftpserver.jks", "conf/users.properties" });
     m.worked(1);
     m.setTaskName("开始生成代码");
     FtpGen gen = new FtpGen();
     String content = gen.generate(null);
     createFolder(project, "src/com");
     createFolder(project, "src/com/lh");
     createFolder(project, "src/com/lh/utils");
     IFile javaFile = project.getProject().getFile(
       "src/com/lh/utils/FtpServerUtils.java");
     project.getProject().refreshLocal(1, m);
     InputStream stream = new ByteArrayInputStream(content
       .getBytes());
     javaFile.create(stream, false, m);
     m.worked(1);
    } catch (Exception e) {
     e.printStackTrace();
    } finally {
     m.done();
    }
   }

  };
  ProgressMonitorDialog d = new ProgressMonitorDialog(null);
  try {
   d.run(true, false, process);
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }

}

 

添加hsql的jar

 

package lhplugin.popup;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class HsqldbAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public HsqldbAction() {
  super();
 }
 //应该是插件jar包的相应jar包的位置
 private String dir = "lib/hsqldb";
 private String sign="hsqldb";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  super.run(dir,sign);
 }


}

添加log4j的类

package lhplugin.popup;

import java.io.IOException;
import java.net.URL;

import lhplugin.Activator;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class Log4jAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public Log4jAction() {
  super();
 }

 // 应该是插件jar包的相应jar包的位置
 private String dir = "lib/log4j";
 private String sign = "log4j";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  IJavaProject project = super.run(dir, sign);
  super.createFile(project,
    new String[] { "lib/log4j/log4j.properties" },
    new String[] { "src/log4j.properties" });

 }

}

添加lucene的类

package lhplugin.popup;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class LunceneAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public LunceneAction() {
  super();
 }
 //应该是插件jar包的相应jar包的位置
 private String dir = "lib/lucene";
 private String sign="lucene";
 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  super.run(dir,sign);
 }

 /**
  * @see IActionDelegate#selectionChanged(IAction, ISelection)
  */
 public void selectionChanged(IAction action, ISelection selection) {
 }

}

添加quartz的类

 

package lhplugin.popup;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class QuartzAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public QuartzAction() {
  super();
 }
 //应该是插件jar包的相应jar包的位置
 private String dir = "lib/quartz";
 private String sign="quartz";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  super.run(dir,sign);
 }


}

添加ssh的类

 

package lhplugin.popup;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class SSHAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public SSHAction() {
  super();
 }
 //应该是插件jar包的相应jar包的位置
 private String dir = "lib/ssh";
 private String sign="ssh";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  super.run(dir,sign);
 }


}

 

添加的类struts2的类

 

package lhplugin.popup;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;

public class Struts2Action extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public Struts2Action() {
  super();
 }

 // 应该是插件jar包的相应jar包的位置
 private String dir = "lib/struts2";
 private String sign = "struts2";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  IJavaProject project = run(dir, sign);
  createFile(project, new String[] { "lib/struts2/struts.xml",
    "lib/struts2/system.xml", "lib/struts2/struts.properties" },
    new String[] { "src/struts.xml", "src/system.xml","src/struts.properties" });
 }

}

添加velocity的类

 

package lhplugin.popup;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class VelocityAction extends SuperDelegate {

 /**
  * Constructor for Action1.
  */
 public VelocityAction() {
  super();
 }
 //应该是插件jar包的相应jar包的位置
 private String dir = "lib/velocity";
 private String sign="velocity";

 /**
  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
  */
 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
 }

 /**
  * @see IActionDelegate#run(IAction)
  */
 public void run(IAction action) {
  super.run(dir,sign);
 }


}

 

在工程下 建立一个lib目录 防止对应的jar包

 

同时建立 jarconfig.properties 用于枚举文件夹的内容 ,因为java没法手动去遍历jar包中某个文件夹里德文件

每个类中  都有两个变量

//用于指定最后发布的jar包中对应action要拷贝jar包的目录

 private String dir = "lib/velocity";

//用来去jarconfig中的key获取所有的文件 方便拷贝
private String sign="velocity";

内容:

ssh=antlr-2.7.6.jar;aopalliance.jar;asm-attrs.jar;asm-commons-2.2.3.jar;asm-util-2.2.3.jar;asm.jar;aspectjlib.jar;aspectjrt.jar;aspectjweaver.jar;c3p0-0.9.1.2.jar;c3p0-0.9.1.jar;cglib-2.1.3.jar;cglib-nodep-2.1_3.jar;commons-attributes-api.jar;commons-attributes-compiler.jar;commons-codec.jar;commons-collections-2.1.1.jar;commons-dbcp.jar;commons-fileupload.jar;commons-httpclient.jar;commons-io.jar;commons-lang.jar;commons-logging-1.0.4.jar;commons-logging.jar;commons-pool.jar;concurrent-1.3.2.jar;connector.jar;dom4j-1.6.1.jar;ehcache-1.2.3.jar;ejb3-persistence.jar;freemarker.jar;hibernate-annotations.jar;hibernate-commons-annotations.jar;hibernate-entitymanager.jar;hibernate-validator.jar;hibernate3.jar;iText-2.0.7.jar;jaas.jar;jacc-1_0-fr.jar;jasperreports-2.0.5.jar;javassist.jar;jaxen-1.1-beta-7.jar;jboss-archive-browsing.jar;jboss-cache.jar;jboss-common.jar;jboss-jmx.jar;jboss-system.jar;jdbc2_0-stdext.jar;jgroups-2.2.8.jar;jotm.jar;jta.jar;jxl.jar;log4j-1.2.11.jar;log4j-1.2.15.jar;mysql-connector-java-5.0.3-bin.jar;oscache-2.1.jar;persistence.jar;poi-3.0.1.jar;portlet-api.jar;proxool-0.8.3.jar;spring-agent.jar;spring-aop.jar;spring-aspects.jar;spring-beans.jar;spring-context.jar;spring-core.jar;spring-jdbc.jar;spring-jms.jar;spring-orm.jar;spring-tomcat-weaver.jar;spring-tx.jar;spring-web.jar;spring-webmvc-portlet.jar;spring-webmvc-struts.jar;spring-webmvc.jar;struts.jar;swarmcache-1.0rc2.jar;velocity-1.5.jar;velocity-tools-view-1.4.jar;xapool.jar;xerces-2.6.2.jar;xml-apis.jar

lucene=IKAnalyzer3.2.5Stable.jar;IKAnalyzer3_javadoc.jar;lucene-analyzers-2.9.3-javadoc.jar;lucene-analyzers-2.9.3.jar;lucene-ant-2.9.3-javadoc.jar;lucene-ant-2.9.3.jar;lucene-bdb-2.9.3-javadoc.jar;lucene-bdb-2.9.3.jar;lucene-bdb-je-2.9.3-javadoc.jar;lucene-bdb-je-2.9.3.jar;lucene-benchmark-2.9.3-javadoc.jar;lucene-benchmark-2.9.3.jar;lucene-collation-2.9.3-javadoc.jar;lucene-collation-2.9.3.jar;lucene-core-2.9.3.jar;lucene-fast-vector-highlighter-2.9.3-javadoc.jar;lucene-fast-vector-highlighter-2.9.3.jar;lucene-highlighter-2.9.3-javadoc.jar;lucene-highlighter-2.9.3.jar;lucene-instantiated-2.9.3-javadoc.jar;lucene-instantiated-2.9.3.jar;lucene-lucli-2.9.3-javadoc.jar;lucene-lucli-2.9.3.jar;lucene-memory-2.9.3-javadoc.jar;lucene-memory-2.9.3.jar;lucene-misc-2.9.3-javadoc.jar;lucene-misc-2.9.3.jar;lucene-queries-2.9.3-javadoc.jar;lucene-queries-2.9.3.jar;lucene-queryparser-2.9.3-javadoc.jar;lucene-queryparser-2.9.3.jar;lucene-regex-2.9.3-javadoc.jar;lucene-regex-2.9.3.jar;lucene-remote-2.9.3-javadoc.jar;lucene-remote-2.9.3.jar;lucene-smartcn-2.9.3-javadoc.jar;lucene-smartcn-2.9.3.jar;lucene-snowball-2.9.3-javadoc.jar;lucene-snowball-2.9.3.jar;lucene-spatial-2.9.3-javadoc.jar;lucene-spatial-2.9.3.jar;lucene-spellchecker-2.9.3-javadoc.jar;lucene-spellchecker-2.9.3.jar;lucene-surround-2.9.3-javadoc.jar;lucene-surround-2.9.3.jar;lucene-swing-2.9.3-javadoc.jar;lucene-swing-2.9.3.jar;lucene-wikipedia-2.9.3-javadoc.jar;lucene-wikipedia-2.9.3.jar;lucene-wordnet-2.9.3-javadoc.jar;lucene-wordnet-2.9.3.jar;lucene-xml-query-parser-2.9.3-javadoc.jar;lucene-xml-query-parser-2.9.3.jar;paoding-analysis.jar;paoding-javadoc.jar

cxf=antlr-2.7.7.jar;aopalliance-1.0.jar;asm-3.3.jar;bcprov-jdk15-1.43.jar;commons-collections-3.2.1.jar;commons-lang-2.5.jar;commons-logging-1.1.1.jar;commons-pool-1.5.2.jar;cxf-2.3.0.jar;cxf-manifest.jar;cxf-xjc-boolean-2.3.0.jar;cxf-xjc-bug671-2.3.0.jar;cxf-xjc-dv-2.3.0.jar;cxf-xjc-ts-2.3.0.jar;FastInfoset-1.2.8.jar;geronimo-activation_1.1_spec-1.1.jar;geronimo-annotation_1.0_spec-1.1.1.jar;geronimo-javamail_1.4_spec-1.7.1.jar;geronimo-jaxws_2.2_spec-1.0.jar;geronimo-jms_1.1_spec-1.1.1.jar;geronimo-servlet_3.0_spec-1.0.jar;geronimo-stax-api_1.0_spec-1.0.1.jar;geronimo-ws-metadata_2.0_spec-1.1.3.jar;jaxb-api-2.2.1.jar;jaxb-impl-2.2.1.1.jar;jaxb-xjc-2.2.1.1.jar;jettison-1.2.jar;jetty-continuation-7.1.6.v20100715.jar;jetty-http-7.1.6.v20100715.jar;jetty-io-7.1.6.v20100715.jar;jetty-server-7.1.6.v20100715.jar;jetty-util-7.1.6.v20100715.jar;jra-1.0-alpha-4.jar;js-1.7R1.jar;jsr311-api-1.1.1.jar;neethi-2.0.4.jar;oro-2.0.8.jar;saaj-api-1.3.jar;saaj-impl-1.3.2.jar;serializer-2.7.1.jar;slf4j-api-1.6.1.jar;slf4j-jdk14-1.6.1.jar;spring-aop-3.0.4.RELEASE.jar;spring-asm-3.0.4.RELEASE.jar;spring-beans-3.0.4.RELEASE.jar;spring-context-3.0.4.RELEASE.jar;spring-core-3.0.4.RELEASE.jar;spring-expression-3.0.4.RELEASE.jar;spring-jms-3.0.4.RELEASE.jar;spring-tx-3.0.4.RELEASE.jar;spring-web-3.0.4.RELEASE.jar;stax2-api-3.0.2.jar;velocity-1.6.4.jar;WHICH_JARS;woodstox-core-asl-4.0.8.jar;wsdl4j-1.6.2.jar;wss4j-1.5.9.jar;xalan-2.7.1.jar;xml-resolver-1.2.jar;xmlbeans-2.4.0.jar;XmlSchema-1.4.7.jar;xmlsec-1.4.3.jar

ftpserver=ftplet-api-1.0.5.jar;ftpserver-core-1.0.5.jar;log4j-1.2.14.jar;mina-core-2.0.0-RC1.jar;slf4j-api-1.5.2.jar;slf4j-log4j12-1.5.2.jar;ftpserver.jks;users.properties
quartz=quartz-1.8.4.jar;quartz-all-1.8.4.jar;quartz-examples-1.8.4.jar;quartz-jboss-1.8.4.jar;quartz-oracle-1.8.4.jar;quartz-weblogic-1.8.4.jar

log4j=log4j-1.2.16.jar;log4j.properties
activeq=activation-1.1.jar;activemq-console-5.1.0.jar;activemq-core-5.1.0-tests.jar;activemq-core-5.1.0.jar;activemq-jaas-5.1.0.jar;activemq-web-5.1.0.jar;camel-core-1.3.0.jar;camel-jms-1.3.0.jar;camel-spring-1.3.0.jar;commons-logging-1.1.jar;geronimo-j2ee-management_1.0_spec-1.0.jar;geronimo-jms_1.1_spec-1.1.1.jar;geronimo-jta_1.0.1B_spec-1.0.1.jar;jaxb-api-2.0.jar;jaxb-impl-2.0.3.jar;stax-1.2.0.jar;stax-api-1.0.jar

ant=ant-antlr.jar;ant-apache-bcel.jar;ant-apache-bsf.jar;ant-apache-log4j.jar;ant-apache-oro.jar;ant-apache-regexp.jar;ant-apache-resolver.jar;ant-apache-xalan2.jar;ant-commons-logging.jar;ant-commons-net.jar;ant-jai.jar;ant-javamail.jar;ant-jdepend.jar;ant-jmf.jar;ant-jsch.jar;ant-junit.jar;ant-launcher.jar;ant-netrexx.jar;ant-nodeps.jar;ant-swing.jar;ant-testutil.jar;ant.jar;build.xml

velocity=antlr-2.7.5.jar;avalon-logkit-2.1.jar;commons-collections-3.2.1.jar;commons-lang-2.4.jar;commons-logging-1.1.jar;jdom-1.0.jar;log4j-1.2.12.jar;maven-ant-tasks-2.0.9.jar;oro-2.0.8.jar;servletapi-2.3.jar;velocity-1.6.4-dep.jar;velocity-1.6.4.jar;werken-xpath-0.9.4.jar

hsqldb=hsqldb.jar;servlet-2_3-fcs-classfiles.zip;sqltool.jar

struts2=commons-logging.jar;freemarker-2.3.16.jar;json-lib-2.1-jdk15.jar;ognl-2.6.11.jar;struts2-core-2.2.1.jar;struts2-json-plugin-2.2.1.jar;struts2-spring-plugin-2.0.11.1.jar;xwork-2.0.4.jar;struts.xml;system.xml;struts.properties

 

 

生成ftp的jar包时 比如要创建一个例子的类 我们可以添加一个生成字符串类的类

 

 

package lhplugin.utils;

import java.util.*;

public class FtpGen
{
  protected static String nl;
  public static synchronized FtpGen create(String lineSeparator)
  {
    nl = lineSeparator;
    FtpGen result = new FtpGen();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package com.lh.utils;" + NL + "import java.io.File;" + NL + "" + NL + "import org.apache.ftpserver.FtpServer;" + NL + "import org.apache.ftpserver.FtpServerFactory;" + NL + "import org.apache.ftpserver.ftplet.FtpException;" + NL + "import org.apache.ftpserver.listener.ListenerFactory;" + NL + "import org.apache.ftpserver.ssl.SslConfigurationFactory;" + NL + "import org.apache.ftpserver.usermanager.PasswordEncryptor;" + NL + "import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;" + NL + "" + NL + "public class FtpServerUtils {" + NL + "" + NL + "/t/**" + NL + "/t * @param args" + NL + "/t * @throws FtpException" + NL + "/t */" + NL + "/tpublic static void startServer() throws FtpException {" + NL + "/t/t// TODO Auto-generated method stub" + NL + "/t/tFtpServerFactory serverFactory = new FtpServerFactory();" + NL + "/t/tListenerFactory factory = new ListenerFactory();" + NL + "/t/tfactory.setPort(21);" + NL + "/t/t// define SSL configuration" + NL + "/t/t/**" + NL + "/t/t * 使用ssl会导致客户端无法连接 SslConfigurationFactory ssl = new" + NL + "/t/t * SslConfigurationFactory(); ssl.setKeystoreFile(new" + NL + "/t/t * File(System.getProperty(/"user.dir/")+/"/conf/ftpserver.jks/"));" + NL + "/t/t * ssl.setKeystorePassword(/"password/");" + NL + "/t/t *  // set the SSL configuration for the listener" + NL + "/t/t * factory.setSslConfiguration(ssl.createSslConfiguration());" + NL + "/t/t * factory.setImplicitSsl(true);" + NL + "/t/t */" + NL + "/t/t// replace the default listener" + NL + "/t/tserverFactory.addListener(/"default/", factory.createListener());" + NL + "" + NL + "/t/tPropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();" + NL + "/t/tuserManagerFactory.setFile(new File(System.getProperty(/"user.dir/")" + NL + "/t/t/t/t+ /"/conf/users.properties/"));" + NL + "/t/tuserManagerFactory.setPasswordEncryptor(new PasswordEncryptor() {" + NL + "" + NL + "/t/t/tpublic String encrypt(String pwd) {" + NL + "/t/t/t/t// TODO Auto-generated method stub" + NL + "/t/t/t/treturn null;" + NL + "/t/t/t}" + NL + "/t/t/t//storedPassword 配置文件中配置的密码 passwordToCheck 是用户输入的密码" + NL + "/t/t/tpublic boolean matches(java.lang.String passwordToCheck," + NL + "/t/t/t/t/tjava.lang.String storedPassword) {" + NL + "/t/t/t/tif (passwordToCheck.equals(storedPassword))" + NL + "/t/t/t/t/treturn true;" + NL + "/t/t/t/treturn false;" + NL + "/t/t/t}" + NL + "" + NL + "/t/t});" + NL + "/t/tserverFactory.setUserManager(userManagerFactory.createUserManager());" + NL + "" + NL + "/t/t// start the server" + NL + "/t/tFtpServer server = serverFactory.createServer();" + NL + "" + NL + "/t/tserver.start();" + NL + "/t/t" + NL + "/t}" + NL + "" + NL + "}";
  protected final String TEXT_2 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    return stringBuffer.toString();
  }
}

后面介绍这个ftpgen类可以使用jet来生成 我们不用手动去拼写字符串

转载于:https://www.cnblogs.com/liaomin416100569/archive/2010/12/02/9331559.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30852367/article/details/99515911

智能推荐

【C语言/C++学习】函数(一)_c语言函数和c++函数学习方法-程序员宅基地

文章浏览阅读542次。文章目录1、引言1、引言_c语言函数和c++函数学习方法

2020 cr节目源_直播源2020-10-10-程序员宅基地

文章浏览阅读4.6k次。#EXTM3U#EXTINF:-1 ,翡翠台https://pullhls3948069e.live.126.net/live/7b23e9c43a5ae5ac5fbc5798ba287286/playlist.m3u8#EXTINF:-1 ,翡翠台http://116.199.5.52/00000000/index.m3u8?&Fsv_ctype=LIVES&Fsv_otype=...

Linux ntp时间服务器的搭建和配置-程序员宅基地

文章浏览阅读1w次,点赞7次,收藏48次。Linux ntp时间服务器的搭建和配置date +"%Z %z"查看ntp服务器与上层ntp的状态【命令】ntpq -premote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先refid:参考上一层ntp主机地址st:stratum阶层when:多少秒前曾经同步过时间poll:下次更新在多少秒后reach:已经向上层ntp服务器要求更新的次数delay:网络延迟offset:时间补偿jit...

Android定位功能实现_android location-程序员宅基地

文章浏览阅读4.4k次,点赞2次,收藏20次。android的定位功能有两种方式:1. 使用第三方地图sdk提供的定位功能。2. 使用sdk的Location实现,借助GPS(高精度)和网络(低精度)实现定位。_android location

Android系统升级那些事儿_edify 源码-程序员宅基地

文章浏览阅读9.7k次,点赞3次,收藏13次。本文描述了Android系统更新要用到的一些概念,用到的硬件、用于烧写的系统和用于系统更新的文件。_edify 源码

动手实现编译器(六)——实现全局变量_判定变量是否为全局变量在编译器哪一步-程序员宅基地

文章浏览阅读566次。我们在上一节中实现了对语句的编译,在这一节中,我们希望向语句中加入变量。实现以下语句:int a;int b;int c;int d;int e;int f;int g;a = 2;b = 3;c = 4;d = 5;e = 6;f = 7;g = 8;print a + b * c / d % e - f + g;这需要变量有以下功能:声明变量使用变量获取存储值给变量赋值相关语法定义变量声明: VarDecl → ‘int’ Ident ‘;’变量赋值:_判定变量是否为全局变量在编译器哪一步

随便推点

TensorFlow 可视化显示 运行过程_pycharm tensorflow 运行状态-程序员宅基地

文章浏览阅读462次。最近两天在跟着莫烦大神修炼TensorFlow,今天学到的是TensorFlow 可视化,是Tensorboard下显示的。现附上莫烦大神的代码,和本机运行的可视化结果和操作。学习视频:Tensorflow 搭建自己的神经网络 (莫烦 Python 教程)https://www.bilibili.com/video/av16001891系统环境:Win7 64位 ..._pycharm tensorflow 运行状态

C++STL中map内存彻底释放方法_c++ map 手动释放-程序员宅基地

文章浏览阅读2w次,点赞7次,收藏46次。最近遇到一个特别占内存的需求。使用STL map/unordered_map,内存无法得到正确释放。再次响应请求,会出现内存溢出的情况。[6453149.107435] Memory cgroup out of memory: Kill process 54949 (******) score 1001 or sacrifice child[6453149.117193] Killed p..._c++ map 手动释放

Qt小例子学习75 - 把QGraphicsItem 保存到文本然后读出来显示_qt qgraphicspathitem 保存 读取saveitem-程序员宅基地

文章浏览阅读768次。Qt小例子学习75 - 把QGraphicsItem 保存到文本然后读出来显示#include "utils.h"#include <QApplication>#include <QDebug>#include <QFile>#include <QGraphicsLineItem>#include <QGraphicsScene>#include <QGraphicsView>#include <QTimer&g_qt qgraphicspathitem 保存 读取saveitem

详解十三款运维监控工具_听云 监控宝-程序员宅基地

文章浏览阅读5k次,点赞3次,收藏42次。目录一、开源工具介绍1、Zabbix2、Nagios3、Ganglia4、Grafana5、Zenoss6、Open-falcon7、Cacti8、天兔开源监控(只适用于mysql、redis、oracle)二、商用运维监控系统篇1、监控宝2、听云3、360网站服务监控4、阿里云监控5、百度云观测纵观我们部署在基础设施当中并始终保持运作的全部测量机制,监控系统无疑是重要性最高的机制之一,但它却常常遭到我们的忽视。如果能够建立起一套坚实的监控_听云 监控宝

本科、硕士和博士有何区别?-程序员宅基地

文章浏览阅读927次。链接:https://www.zhihu.com/question/24963114编辑:深度学习与计算机视觉声明:仅做学术分享,侵删作者:安若素https://www.zhihu.co...

如何对webbrowser和IE编程(一)_vb webbrowser internetexplorer-程序员宅基地

文章浏览阅读536次。 如何对webbrowser和IE编程一、因为工作缘故,需要研究对IE编程,所以翻译了MS的有关资料,供参考。IE的体系WebBrowser Host首先,必须有COM的基础知识,因为IE本身就是COM技术的典型应用。我们看到最上层是WebBrowser的宿主(Host),也就是任何你想重用(ReUse)webbrows_vb webbrowser internetexplorer

推荐文章

热门文章

相关标签