1、Eclipse 中插件开发多语言的实现
为了使用 .properties 文件,需要在 META-INF/MANIFEST.MF 文件中定义:
Bundle-Localization: plugin
这样就会自动加载 plugin.properties 文件(中文找 plugin_zh_CN.properties)
然后在 plugin.xml 文件中,将字符串替换为 %key 就可以了
建议先使用 Eclipse 的外部化字符串目录:
Bundle-Localization: OSGI-INF/l10n/plugin
2、Eclipse 插件开发初始化隐藏某工具栏按钮
在网上找了好久都找不到解决办法,最后搜索 eclipse 安装目录,从它自己的插件里面找到样例了。样例来自 org.eclipse.jdt.ui/plugin.xml
<extension
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="*">
<!-- 注意这里的 id 是 action 或 command 的 id -->
<hiddenToolBarItem id="org.eclipse.jdt.ui.actions.OpenProjectWizard">
</hiddenToolBarItem>
</perspectiveExtension>
3、插件中获取 Eclipse 版本号
01.String sEclipseVersion = System.getProperty("osgi.framework.version");
4、插件中获取路径
// 得到插件所在的路径
Platform.asLocalURL(Platform.getBundle("your plugin ID").getEntry("")).getFile();
// 得到当前工作空间的路径
Platform.getInstanceLocation().getURL().getFile();
// 得到当前工作空间下的所有工程
ResourcesPlugin.getWorkspace().getRoot().getProjects();
// 得到某 PLUGIN 的路径:
Platform.getBundle("mypluginid").getLocation().
// eclipse采用osgi后好像还可以:
Activator.getDefault().getBundle().getLocation(); //前提是这个插件有Activator这个类.这个类继承了ECLIPSE的Plugin类
// eclipse采用osgi前好像好像是:
MyPlugin.getDefault().getBundle().getLocation(); //前提是这个插件有MyPlugin这个类.这个类继承了ECLIPSE的Plugin类
// 得到工作区路径:
Platform.getlocation();
// 或 ResourcesPlugin.getWorkspace(); 好像 Platform.getInstanceLocation() 也可行
// 得到ECLIPSE安装路径
Platform.getInstallLocation();
// 从插件中获得绝对路径:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath();
// 通过文件得到 Project:
IProject project = ((IFile)o).getProject();
// 通过文件得到全路径:
String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();
// 得到整个Workspace的根:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// 从根来查找资源:
IResource resource = root.findMember(new Path(containerName));
// 从Bundle来查找资源:
Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, filePath);
// 得到 Appliaction workspace:
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();
// 得到 runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();
// 从编辑器来获得编辑文件
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput)
{
IFile file = ((IFileEditorInput)input).getFile();
}
// 获取插件的绝对路径:
FileLocator.resolve(BuildUIPlugin.getDefault().getBundle().getEntry("/")).getFile();
5、添加myeclipse JAVAEE Library 与User Library
IClasspathEntry myEclipseJAVAEE5 =JavaCore.newContainerEntry(new Path("melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"));
IClasspathEntry myEclipseUCITPortletDev =JavaCore.newContainerEntry(new Path("org.eclipse.jdt.USER_LIBRARY/UCITPortletDev"));
IClasspathEntry myEclipseUCITPortletDev =JavaCore.newContainerEntry(new Path("org.eclipse.jdt.USER_LIBRARY/UCITPortletDev"));
6、利用Ifile向项目中写文件
/**
* jar文件输入流
* @param path
* @return
*/
private InputStream fileInput(File path){
try {
FileInputStream fis=new FileInputStream(path);
return fis;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* Adds a new file to the project.
*
* @param container
* @param path
* @param contentStream
* @param monitor
* @throws CoreException
*/
private void addFileToProject(IContainer container, Path path,
InputStream contentStream, IProgressMonitor monitor)
throws CoreException {
final IFile file = container.getFile(path);
if (file.exists()) {
file.setContents(contentStream, true, true, monitor);
} else {
file.create(contentStream, true, monitor);
}
}
* jar文件输入流
* @param path
* @return
*/
private InputStream fileInput(File path){
try {
FileInputStream fis=new FileInputStream(path);
return fis;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* Adds a new file to the project.
*
* @param container
* @param path
* @param contentStream
* @param monitor
* @throws CoreException
*/
private void addFileToProject(IContainer container, Path path,
InputStream contentStream, IProgressMonitor monitor)
throws CoreException {
final IFile file = container.getFile(path);
if (file.exists()) {
file.setContents(contentStream, true, true, monitor);
} else {
file.create(contentStream, true, monitor);
}
}
//写入自动生成portlet环境的jar包
IContainer container = (IContainer) project;
IProgressMonitor monitor = new NullProgressMonitor();
Path autoJar=new Path(WEBROOT+FILESEPARATOR+WEBINF+FILESEPARATOR +LIB+FILESEPARATOR+"UcitPortletDev.jar"); //项目路径
InputStream jarIS=fileInput(new File("d:/PortletAuto.jar")); //本地文件路径
//写入自动生成portlet环境的xml配置文件
Path autoConfigXML=new Path("src"+FILESEPARATOR+"service_portlet.xml"); //项目路径
InputStream XMLIS=fileInput(new File(selectConfigPath)); //本地文件路径
try {
addFileToProject(container,autoJar,jarIS,monitor); //Jar
monitor = new NullProgressMonitor();
addFileToProject(container,autoConfigXML,XMLIS,monitor); //XML
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if (jarIS!=null){
jarIS.close();
}
if (XMLIS!=null){
XMLIS.close();
}
}
IContainer container = (IContainer) project;
IProgressMonitor monitor = new NullProgressMonitor();
Path autoJar=new Path(WEBROOT+FILESEPARATOR+WEBINF+FILESEPARATOR +LIB+FILESEPARATOR+"UcitPortletDev.jar"); //项目路径
InputStream jarIS=fileInput(new File("d:/PortletAuto.jar")); //本地文件路径
//写入自动生成portlet环境的xml配置文件
Path autoConfigXML=new Path("src"+FILESEPARATOR+"service_portlet.xml"); //项目路径
InputStream XMLIS=fileInput(new File(selectConfigPath)); //本地文件路径
try {
addFileToProject(container,autoJar,jarIS,monitor); //Jar
monitor = new NullProgressMonitor();
addFileToProject(container,autoConfigXML,XMLIS,monitor); //XML
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if (jarIS!=null){
jarIS.close();
}
if (XMLIS!=null){
XMLIS.close();
}
}
7、获取Eclipse当前项目
public static IProject getCurrentProject(){
ISelectionService selectionService =
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
IProject project = null;
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof IResource) {
project= ((IResource)element).getProject();
} else if (element instanceof PackageFragmentRootContainer) {
IJavaProject jProject =
((PackageFragmentRootContainer)element).getJavaProject();
project = jProject.getProject();
} else if (element instanceof IJavaElement) {
IJavaProject jProject= ((IJavaElement)element).getJavaProject();
project = jProject.getProject();
}
}
return project;
}
ISelectionService selectionService =
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
IProject project = null;
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof IResource) {
project= ((IResource)element).getProject();
} else if (element instanceof PackageFragmentRootContainer) {
IJavaProject jProject =
((PackageFragmentRootContainer)element).getJavaProject();
project = jProject.getProject();
} else if (element instanceof IJavaElement) {
IJavaProject jProject= ((IJavaElement)element).getJavaProject();
project = jProject.getProject();
}
}
return project;
}
相关推荐
Eclipse中使用Tomcat插件的遇到的一些问题,包括插件安装及开发过程中经常遇到的一些问题
安装ophone 开发环境时遇到了 log4j插件未找到的问题。安装该包后解决
分析Eclipse的体系结构,提出了Eclipse插件开发在嵌入式系统开发领 域中的优势。 (2)详细地介绍了Eclipse平台的结构和特性,分析了Eclipse平台上插件 开发的相关技术。介绍了Eclipse的插件机制,插件的部署与激活、...
这些插件将 C/C++ 透视图添加到 Eclipse 工作台(Workbench)中, 现在后者可以用许多视图和向导以及高级编辑和调试支持来支持 C/C++ 开发。 由于其复杂性,CDT 被分成几个组件,它们都采用独立插件的形式。 每个...
Eclipse安装 Eclipse是一款非常优秀的开源IDE,非常适合Java开发,由于支持插件技术,受到了越来越多的... 我的开发环境是JDK1.4.2+Eclipse3.0+Windows XP SP2,如果你在其他平台上遇到任何问题,欢迎来信交流。
在java开发过程中,总是遇到一些封装好的class文件,想看看class文件中的代码如何编写的,这时候就需要反编译插件了。安装上之后就可以看到源代码了。更好的完成开发工作
遇到这种情况可以采用离线的方式配置ADT eclipse 安卓开发环境。 使用方法: 1.启动Eclipse,然后在菜单栏上选择 Help > Install New Software 2.单击 Add 按钮,在右上角 3.在"Add Repository"对话框,单击"Archive" ...
1、Struts环境支持:参考 9.2的Struts安装以及9.7的StrutsIDE插件安装。 2、Spring环境支持:参考14.1的Spring安装。 3、Hibernate环境支持:参考13.2的Hibernate开发环境。 4、Web开发环境支持:参考6.2的WTP Web...
项目中遇到的问题.avi │ 13.quartz.avi │ aa.quartz框架.avi │ 淘淘商城第十二天笔记.docx │ ├─补充1:拔高课程(Redis3.0持久化、集群、MySQL5.6优化、Tomcat7优化) │ │ 打开必读.txt │ │ │ ├─课前...
压缩包中的“华视CVR100读卡器sdk二次开发”压缩包是可以直接导入到eclipse中的java项目,其中我自定义了方法,读卡成功后直接将姓名和身份证用post推送到自定义的url中。 Jnative插件是32位的,所以用的jdk6也是32...
Android中ADT插件的安装,许多新手在建立基于eclipse的android开发环境是都会遇到adt的安装问题,我也如是,此文档摘自网络希望对andriod开发环境的搭建有所帮助。
安装Eclipse插件Android为Eclipse IDE提供了一个自定义插件,称为Android开发工具(ADT)。 该插件提供了一个功能强大的集成环境,可在其中开发Android应用程序。 它扩展了Eclipse的功能,使您可以快速设置新的...
Spring MVC 3.2.8支持的最高Hibernate版本是4.1.7,更高的Hibernate版本和Spring MVC 3.2.8组合会遇到兼容问题。 4、Hibernate集成二级缓存框架Ehcache。 5、数据库是MySQL、Oracle和SQL Server,Hibernate的Dialect...
尝试做过插件开发的同学应该都遇到,插件资源id和宿主程序资源id可能相同,导致获取的资源不是想要的资源。 此问题其实在android提供的编译器aapt中早已提供了支持。 12、需要关注PluginTest工程的ant....
maven2的插件,用于在eclipse下进行maven2的快速配置 打开eclipse .选择菜单 window ->preferences ; 在新打开的对话框的左边的一列会看到一个名为Maven2的选项。鼠标单击,然后点击右边的Local Repository Folder ...
2.3.1 Java、Eclipse和ADT插件安装 2.3.2 设定AndroidSDKHome 2.4 MacOS一族——苹果开发环境搭建 2.5 本章小结 第3章 清点可用资本——AndroidSDK介绍 3.1 AndroidSDK基础 3.2 深入探寻AndroidSDK的密码 3.2.1 ...
经过问题分析,代码查看,是开发库的问题,解决了开发库问题,就正常了。 十七、网狐荣耀版李奎劈鱼游戏,捕鱼游戏提示“非法组件的解决办法” 在使用网狐荣耀版时,捕鱼进入游戏时提示非法组件,如下图,这个是...
1、ctk插件式开发,便于维护,类似eclipse中的plugin 2、下载安装ctk代码编译 https://github.com/knowledge0603/ctk-source 或者 https://github.com/commontk/CTK 3、下载2步骤文件,解压文件到CTK文件夹路径 在...
(安装方法:https://blog.csdn.net/zj499063104/article/details/91606978) 作为java初学者用eclipse开发时,经常会遇到一个问题,当我们想查看函数(方法)的具体实现时,会通过F5或者Ctrl+鼠标左键,进入函数。...
运行HelloAndroid项目 调试HelloAndroid项目,首先将Eclipse开发工具的工作界面切换到DDMS: 实验过程中发现的问题以及解决问题的方法 在安装Android SDK的时候,遇到信息"Failed to fetch URL…"的错误提示,然后...