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;
}
相关推荐
EMF(Eclipse Modeling Framework)插件是 Eclipse 中的一个重要插件,提供了模型驱动的开发环境。安装 EMF 插件的步骤如下: 1. 在 Eclipse 的主菜单,点击 help,选择 Install New Software。 2. 在打开的 ...
Eclipse中使用Tomcat插件的遇到的一些问题,包括插件安装及开发过程中经常遇到的一些问题
在NC65共享开发环境中,可能会遇到各种错误和问题。例如,可能会遇到nclog下的Spring关键字错误。为了解决这些问题,需要了解NC65共享开发环境中的各种配置选项和参数,并且需要了解错误的原因和解决方法。 结语 NC...
安装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文件中的代码如何编写的,这时候就需要反编译插件了。安装上之后就可以看到源代码了。更好的完成开发工作
本文总结了在 Windows XP 平台下安装 Eclipse + MinGW + Qt 的步骤和解决方案,以便开发 C++ 项目。在安装过程中遇到的问题和解决方法也进行了总结。 一、下载和安装 Qt Qt 是一个跨平台的应用程序开发框架,提供...
在 Windows 下使用 Eclipse 开发 C++ 项目时,可能会遇到 “Lauch failed. Binary not found” 的错误,这个问题的解决方案可以分为以下几个方面: 1. 项目设置:在 Eclipse 中,项目的设置非常重要,特别是当我们...
遇到这种情况可以采用离线的方式配置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...
ADT 是 Android 开发工具插件,用于在 Eclipse 中开发 Android 应用程序。安装 ADT 之后,需要配置 ADT,包括设置环境变量、添加插件等。 二、创建第一个 Android 项目 HelloAndroid 创建第一个 Android 项目 ...
在日常开发中,我们经常会遇到一些问题,例如智能提示不太理想、代码优化、性能优化等。这时,我们可以通过查看官方文档、社区论坛、博客等来解决问题。同时,我们也可以通过分享和讨论来帮助他人解决问题。 ...
经过问题分析,代码查看,是开发库的问题,解决了开发库问题,就正常了。 十七、网狐荣耀版李奎劈鱼游戏,捕鱼游戏提示“非法组件的解决办法” 在使用网狐荣耀版时,捕鱼进入游戏时提示非法组件,如下图,这个是...
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...