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

智能推荐

class和struct的区别-程序员宅基地

文章浏览阅读101次。4.class可以有⽆参的构造函数,struct不可以,必须是有参的构造函数,⽽且在有参的构造函数必须初始。2.Struct适⽤于作为经常使⽤的⼀些数据组合成的新类型,表示诸如点、矩形等主要⽤来存储数据的轻量。1.Class⽐较适合⼤的和复杂的数据,表现抽象和多级别的对象层次时。2.class允许继承、被继承,struct不允许,只能继承接⼝。3.Struct有性能优势,Class有⾯向对象的扩展优势。3.class可以初始化变量,struct不可以。1.class是引⽤类型,struct是值类型。

android使用json后闪退,应用闪退问题:从json信息的解析开始就会闪退-程序员宅基地

文章浏览阅读586次。想实现的功能是点击顶部按钮之后按关键字进行搜索,已经可以从服务器收到反馈的json信息,但从json信息的解析开始就会闪退,加载listview也不知道行不行public abstract class loadlistview{public ListView plv;public String js;public int listlength;public int listvisit;public..._rton转json为什么会闪退

如何使用wordnet词典,得到英文句子的同义句_get_synonyms wordnet-程序员宅基地

文章浏览阅读219次。如何使用wordnet词典,得到英文句子的同义句_get_synonyms wordnet

系统项目报表导出功能开发_积木报表 多线程-程序员宅基地

文章浏览阅读521次。系统项目报表导出 导出任务队列表 + 定时扫描 + 多线程_积木报表 多线程

ajax 如何从服务器上获取数据?_ajax 获取http数据-程序员宅基地

文章浏览阅读1.1k次,点赞9次,收藏9次。使用AJAX技术的好处之一是它能够提供更好的用户体验,因为它允许在不重新加载整个页面的情况下更新网页的某一部分。另外,AJAX还使得开发人员能够创建更复杂、更动态的Web应用程序,因为它们可以在后台与服务器进行通信,而不需要打断用户的浏览体验。在Web开发中,AJAX(Asynchronous JavaScript and XML)是一种常用的技术,用于在不重新加载整个页面的情况下,从服务器获取数据并更新网页的某一部分。使用AJAX,你可以创建异步请求,从而提供更快的响应和更好的用户体验。_ajax 获取http数据

Linux图形终端与字符终端-程序员宅基地

文章浏览阅读2.8k次。登录退出、修改密码、关机重启_字符终端

随便推点

Python与Arduino绘制超声波雷达扫描_超声波扫描建模 python库-程序员宅基地

文章浏览阅读3.8k次,点赞3次,收藏51次。前段时间看到一位发烧友制作的超声波雷达扫描神器,用到了Arduino和Processing,可惜啊,我不会Processing更看不懂人家的程序,咋办呢?嘿嘿,所以我就换了个思路解决,因为我会一点Python啊,那就动手吧!在做这个案例之前先要搞明白一个问题:怎么将Arduino通过超声波检测到的距离反馈到Python端?这个嘛,我首先想到了串行通信接口。没错!就是串口。只要Arduino将数据发送给COM口,然后Python能从COM口读取到这个数据就可以啦!我先写了一个测试程序试了一下,OK!搞定_超声波扫描建模 python库

凯撒加密方法介绍及实例说明-程序员宅基地

文章浏览阅读4.2k次。端—端加密指信息由发送端自动加密,并且由TCP/IP进行数据包封装,然后作为不可阅读和不可识别的数据穿过互联网,当这些信息到达目的地,将被自动重组、解密,而成为可读的数据。不可逆加密算法的特征是加密过程中不需要使用密钥,输入明文后由系统直接经过加密算法处理成密文,这种加密后的数据是无法被解密的,只有重新输入明文,并再次经过同样不可逆的加密算法处理,得到相同的加密密文并被系统重新识别后,才能真正解密。2.使用时,加密者查找明文字母表中需要加密的消息中的每一个字母所在位置,并且写下密文字母表中对应的字母。_凯撒加密

工控协议--cip--协议解析基本记录_cip协议embedded_service_error-程序员宅基地

文章浏览阅读5.7k次。CIP报文解析常用到的几个字段:普通类型服务类型:[0x00], CIP对象:[0x02 Message Router], ioi segments:[XX]PCCC(带cmd和func)服务类型:[0x00], CIP对象:[0x02 Message Router], cmd:[0x101], fnc:[0x101]..._cip协议embedded_service_error

如何在vs2019及以后版本(如vs2022)上添加 添加ActiveX控件中的MFC类_vs添加mfc库-程序员宅基地

文章浏览阅读2.4k次,点赞9次,收藏13次。有时候我们在MFC项目开发过程中,需要用到一些微软已经提供的功能,如VC++使用EXCEL功能,这时候我们就能直接通过VS2019到如EXCEL.EXE方式,生成对应的OLE头文件,然后直接使用功能,那么,我们上篇文章中介绍了vs2017及以前的版本如何来添加。但由于微软某些方面考虑,这种方式已被放弃。从上图中可以看出,这一功能,在从vs2017版本15.9开始,后续版本已经删除了此功能。那么我们如果仍需要此功能,我们如何在新版本中添加呢。_vs添加mfc库

frame_size (1536) was not respected for a non-last frame_frame_size (1024) was not respected for a non-last-程序员宅基地

文章浏览阅读785次。用ac3编码,执行编码函数时报错入如下:[ac3 @ 0x7fed7800f200] frame_size (1536) was not respected for anon-last frame (avcodec_encode_audio2)用ac3编码时每次送入编码器的音频采样数应该是1536个采样,不然就会报上述错误。这个数字并非刻意固定,而是跟ac3内部的编码算法原理相关。全网找不到,国内音视频之路还有很长的路,音视频人一起加油吧~......_frame_size (1024) was not respected for a non-last frame

Android移动应用开发入门_在安卓移动应用开发中要在活动类文件中声迷你一个复选框变量-程序员宅基地

文章浏览阅读230次,点赞2次,收藏2次。创建Android应用程序一个项目里面可以有很多模块,而每一个模块就对应了一个应用程序。项目结构介绍_在安卓移动应用开发中要在活动类文件中声迷你一个复选框变量

推荐文章

热门文章

相关标签