tomcat9扩展php 插件,Eclipse插件开发tomcat扩展
介紹 本文介紹如何給Eclipse自帶的tomcat插件添加一些功能。
右鍵菜單擴展 添加擴展點 org.eclipse.ui.popupMenus [codesyntax lang="xml"]
id="org.eclipse.jst.server.tomcat.ui.serveractions" objectClass="org.eclipse.wst.server.core.IServer">
enablesFor="1" id="surenpi.com.dev.debugger.tomcat.openserverdiraction"
label="Open Deploy Directory">
id="org.eclipse.jst.server.tomcat.ui.serveractions" objectClass="org.eclipse.wst.server.ui.internal.view.servers.ModuleServer">
enablesFor="1" id="surenpi.com.dev.debugger.tomcat.openmodulediraction"
label="Open Deploy Directory">
[/codesyntax] 我們實現的功能是通過右鍵菜單打開tomcat下部署的項目: [codesyntax lang="java"]
/**
* http://surenpi.com
*/
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jst.server.tomcat.core.internal.TomcatServerBehaviour;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.ui.IServerModule;
/**
* @author surenpi.com
* @since jdk1.6
* 2015年8月19日
*/
public class OpenDirAction implements IObjectActionDelegate {
private IServer selectedServer;
private IModule selectedModule;
@Override
public void run(IAction action) {
if(selectedServer == null) {
return;
}
IPath targetPath = null;
try {
Class> clazz = Class.forName("org.eclipse.jst.server.tomcat.core.internal.TomcatServerBehaviour");
TomcatServerBehaviour behaviour = (TomcatServerBehaviour) selectedServer.loadAdapter(clazz, null);
if(selectedModule != null) {
targetPath = behaviour.getModuleDeployDirectory(selectedModule);
} else {
targetPath = behaviour.getRuntimeBaseDirectory();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if(targetPath != null) {
File file = targetPath.toFile();
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().open(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
if ((!selection.isEmpty()) && ((selection instanceof IStructuredSelection))) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
if ((obj instanceof IServer)) {
this.selectedServer = ((IServer) obj);
} else if ((obj instanceof IServerModule)) {
IServerModule sm = (IServerModule) obj;
IModule[] module = sm.getModule();
this.selectedModule = module[(module.length - 1)];
if (this.selectedModule != null)
this.selectedServer = sm.getServer();
}
}
}
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
} [/codesyntax]
視圖工具欄擴展 添加擴展點 org.eclipse.ui.viewActions [codesyntax lang="xml"]
point="org.eclipse.ui.viewActions">
targetID="org.eclipse.wst.server.ui.ServersView">
label="Open Server Directory"
menubarPath="additions"
toolbarPath="additions"
icon="icons/explore.png"
tooltip="Open Server Directory"
class="surenpi.com.dev.explore.tomcat.OpenTomcatDir"
enablesFor="1">
[/codesyntax] 實現類與上面的OpenDirAction相同,只是要實現接口org.
eclipse.
ui.IViewActionDelegate
參考
如果你想知道怎么才能把菜單或者工具欄配置到你希望出現的地方,可以看這篇文章。
總結
以上是生活随笔為你收集整理的tomcat9扩展php 插件,Eclipse插件开发tomcat扩展的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java servlet hellowo
- 下一篇: nginx php mysql分离,详解