try {<br /> Runtime.getRuntime()<br /> .exec("cmd.exe /C start", null, new File("c:/"));<br /> System.out.println("finish");<br /> } catch (IOException e) {<br /> e.printStackTrace();<br /> }
可以通過java 代碼開啟一個dos視窗
if (selection instanceof IStructuredSelection) {<br /> Object sel = ((IStructuredSelection)selection).getFirstElement();</p><p> if (sel instanceof PlatformObject) {<br /> PlatformObject p = (PlatformObject)sel;<br /> IResource resource = (IResource)p.getAdapter(IResource.class);<br /> if (resource != null) {<br /> return getPath(resource);<br /> }<br /> }<br /> if (sel instanceof IResource) {<br /> IResource res = (IResource)sel;<br /> if (res != null) {<br /> return getPath(res);<br /> }<br /> }</p><p> if (sel instanceof IJavaElement) {<br /> IJavaElement je = (IJavaElement)sel;<br /> try {<br /> IResource correspondingResource = je.getCorrespondingResource();<br /> if (correspondingResource != null)<br /> getPath(correspondingResource);<br /> }<br /> catch (JavaModelException localJavaModelException) {<br /> }<br /> }<br /> if (sel instanceof IPluginModel) {<br /> IPluginModel mod = (IPluginModel)sel;<br /> String installLocation = mod.getInstallLocation();<br /> return installLocation;<br /> }<br /> if (sel instanceof IJarEntryResource) {<br /> IJarEntryResource jar = (IJarEntryResource)sel;<br /> IPath fullPath = jar.getFullPath();</p><p> return fullPath.makeAbsolute().toOSString();<br /> }</p><p> if (sel instanceof IAdaptable) {<br /> IAdaptable ad = (IAdaptable)sel;</p><p> IResource resource = (IResource)ad.getAdapter(IResource.class);<br /> if (resource != null) {<br /> return getPath(resource);<br /> }<br /> }
根據ISelection取得 ISelection得到的資源路徑
public void logError(String msg, Throwable t) {<br /> ILog log = getDefault().getLog();<br /> Status s = new Status(4, PLUGIN_ID, msg, t);<br /> log.log(s);<br />}
外掛程式在啟動並執行時候運行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