try { Runtime.getRuntime() .exec("cmd.exe /C start", null, new File("c:/")); System.out.println("finish"); } catch (IOException e) { e.printStackTrace(); }
可以通过java 代码打开一个dos窗口
if (selection instanceof IStructuredSelection) { Object sel = ((IStructuredSelection)selection).getFirstElement(); if (sel instanceof PlatformObject) { PlatformObject p = (PlatformObject)sel; IResource resource = (IResource)p.getAdapter(IResource.class); if (resource != null) { return getPath(resource); } } if (sel instanceof IResource) { IResource res = (IResource)sel; if (res != null) { return getPath(res); } } if (sel instanceof IJavaElement) { IJavaElement je = (IJavaElement)sel; try { IResource correspondingResource = je.getCorrespondingResource(); if (correspondingResource != null) getPath(correspondingResource); } catch (JavaModelException localJavaModelException) { } } if (sel instanceof IPluginModel) { IPluginModel mod = (IPluginModel)sel; String installLocation = mod.getInstallLocation(); return installLocation; } if (sel instanceof IJarEntryResource) { IJarEntryResource jar = (IJarEntryResource)sel; IPath fullPath = jar.getFullPath(); return fullPath.makeAbsolute().toOSString(); } if (sel instanceof IAdaptable) { IAdaptable ad = (IAdaptable)sel; IResource resource = (IResource)ad.getAdapter(IResource.class); if (resource != null) { return getPath(resource); } }
根据ISelection取得 ISelection得到的资源路径
public void logError(String msg, Throwable t) { ILog log = getDefault().getLog(); Status s = new Status(4, PLUGIN_ID, msg, t); log.log(s); }
插件在运行的时候运行System.out.println 是不起作用的,必须使用记录日志的方式来显示打印信息,可以用以上方式
mvn 执行java main程序:
mvn exec:java -Dexec.mainClass=com.koubei.kac.alipaytaobaocooperate.CAEAlipayCooperate
详细:http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html
如果碰上一个本地仓库中没有的jar包,那需要事先安装到本地的jar中,可以尝试使用下面的命令:
mvn install:install-file -Dpackaging=jar -DartifactId=koubei-core-web-tag -DgroupId=com.koubei -Dfile=./koubei-cor
e-web-tag-1.0.3-20110506.080829-2.jar -Dversion=1.0.3-SNAPSHOT
下载jar代码的同时下载代码包的源代码包:
mvn eclipse:eclipse -DdownloadSources=true (这里一定要用eclipse:eclipse 这个 插件,不然的话不会下载源代码包)