打开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来生成 我们不用手动去拼写字符串