Eclipse IDE插件开发:将文件从插件jar复制到活动项目文件夹 [英] Eclipse IDE plugin development: copy files from plugin jar to active project folder
问题描述
我正在为eclipse开发一个插件。插件的目的是使用Acceleo生成代码。
I am developing a plug-in for eclipse. The purpose of the plug-in is to generate code by using Acceleo.
我想将目录的内容从生成器插件jar复制到文件夹中插件生成代码后生成文件的位置。
I want to copy the contents of a directory from the generator plug-in jar, into the folder where files have been generated after the plug-in has finished generating the code.
org.plugin.generator / framework
||
将内容复制到:
||
\ /
工作区/ ProjectFolder / generatedFiles / classes
org.plugin.generator/framework || copy contents to: || \/ Workspace/ProjectFolder/generatedFiles/classes
我可以获取路径,但我无法弄清楚如何提取jar中的框架文件夹并将其内容复制到当前项目文件夹中。
I can get the paths, but I can't figure out how to extract the framework folder from the jar and copy its contents in the current project folder.
任何人都可以提供一些提示吗?我是Eclipse插件开发的初学者。
另外,这是我的第一个问题,虽然我已经浏览了1 - 2年。
Can anyone please provide some tips? I am a beginner at Eclipse plug-in development. Also, this is my first question here, although I have been browsing for 1-2 years.
推荐答案
这里是一个粗略的代码片段,用于从插件中读取任何文件并将其写入项目。我不知道是否有办法列出文件夹文件夹中的文件,但您可以随时对需要复制的文件列表进行硬编码。
Here is a rough code snippet to read any file from a plugin and write it to a project. I do not know if there is a way to list files in a bundle folder, but you can always hardcode the list of files you need to copy.
Bundle bundle = Platform.getBundle( "your.plugin.id" );
InputStream stream = FileLocator.openStream( bundle, "path.in.plugin", false );
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( "your.project" );
IFile file = project.getFile( "something/abc.txt" );
file.create( stream, true, null );
您需要在上面的代码段中添加异常处理和关闭流。
You will need to add exception handling and closing of the stream to the above snippet.
这篇关于Eclipse IDE插件开发:将文件从插件jar复制到活动项目文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!