我在JAR中有一个.scala文件,如何打开不属于jar的代码? 对于一些额外的精度,jar文件不在类路径上。
这是我的代码示例。它部分工作,jar上的文件是打开的,但为此我从文件夹“lib”创建它。
你有没有想过要在文件夹上创建文件?
谢谢!
protected Object openDialogBox(Control cellEditorWindow, Object value, String jarFileName)
throws CoreException, IOException {
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject myProject = myWorkspaceRoot.getProject(ActiveProject.getNameProject());
String fileProgramName = (String) value;
InputStream stream;
final boolean readOnly = (jarFileName != null);
if (myProject.exists() && myProject.isOpen()) {
IFolder sourceFolder = myProject.getFolder( (jarFileName != null) ? "lib" : "src" );
if (sourceFolder.exists()) {
final IFile programFile = sourceFolder.getFile(fileProgramName);
if ( jarFileName != null ) {
programFile.delete(true, new NullProgressMonitor());
stream = JarUtil.getProgramFromJar(jarFileName, fileProgramName);
}
else {
stream = createContentStream(myProject.getName(), programFile.getName().replace(".scala", ""));
}
if (!programFile.exists()) {
// create the file
programFile.create(stream, true, new NullProgressMonitor());
}
programFile.refreshLocal(IResource.DEPTH_ZERO, null);
stream.close();
cellEditorWindow.getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
ResourceAttributes myAttributes = programFile.getResourceAttributes();
if (myAttributes == null) {
myAttributes = new ResourceAttributes();
}
myAttributes.setReadOnly(readOnly);
try {
programFile.setResourceAttributes(myAttributes);
} catch (CoreException e) {
e.printStackTrace();
}
IDE.openEditor(page, programFile, true);
} catch (PartInitException e) {
}
}
});
return value;
}
return null;
}
return null;
}