Where is addStdResource in Maia?
I'm trying to load an xml schema file. I used to use this code for it:
ExternalResourceManager.getInstance().addStdResource(namespace, filename, getClass());
But now IDEA doesn't recognize addStdResource - only addResource.
What should I do?
请先登录再写评论。
use extension point <standardResourceProvider>
then register like this
HTH,
Yann
Ok, great but what do I do with the standardResourceProvider? Do I have to register it somewhere because registerResources is never called.
I put the code in the initComponent of my main ApplicationComponent class. Maybe that's too late or something?
public void initComponent() {
standardResourceProvider = new StandardResourceProvider() {
public void registerResources(ResourceRegistrar resourceRegistrar) {
System.out.println("registering resource");
resourceRegistrar.addStdResource("http://www.bindows.net/Schema/3.0/", "BindowsAdfSchema.xsd", MiniLauncherComponent.class);
}
};
}
you must use and declare it as extensionpoint in your plugin.xml:
It's still not getting called. This is the entire contents of my plugin.xml:
<idea-plugin version="2">
<name>Plugin name here</name>
<description>short description of the plugin</description>
<version>1.0</version>
<vendor>YourCompany</vendor>
<idea-version since-build="8000"/>
<application-components>
<!-- Add your application components here -->
</application-components>
<project-components>
<!-- Add your project components here -->
</project-components>
<actions>
<!-- Add your actions here -->
</actions>
<extensions defaultExtensionNs="com.intellij">
<standardResourceProvider implementation="com.segerfeldt.minilauncher.schemas.SchemaResources"/>
</extensions>
</idea-plugin>
And I made a very simple class that just implements the interface.
public class SchemaResources implements StandardResourceProvider {
public void registerResources(ResourceRegistrar resourceRegistrar) {
System.out.println("res prov");
resourceRegistrar.addStdResource("http://www.bindows.net/Schema/3.0/", "BindowsAdfSchema.xsd", MiniLauncherComponent.class);
}
}
I'm not getting the system.out message. No error messages. What could be wrong?
<extensions> must be before <application-components>
please verify your order against other plugin.xml files
I moved the extensions tag above it but that didn't help either.
I have plowed through all plugin.xml files in the IDEA 8 dev package (there seem to be no dev package for Maia) but not a single one uses the standardResourceProvider tag.
Another thing: when using this dtd: <!DOCTYPE idea-plugin PUBLIC "Plugin/DTD" "http://plugins.intellij.net/plugin.dtd">
IDEA complain that "Element type standardResourceProvider must be declared". Might not be important but I'm grasping at straws here.
I have found out that if I create a new plugin from scratch with just an ApplicationComponent and a class that implements StandardResourceProvider it works.
Unless I set the -Xmx1024m switch though IntelliJ is acting really flaky (I wonder if this has anything to do with me being on snow leopard). My problem now is that nothing of this works in my real plugin and I don't have a clue what breaks it.
Anyone feel like taking a look at my plugin?
Btw: When creating a new plugin the auto generated plugin.xml has the extensions section at the bottom. Don't know if it really matters yet though as I always move it to the top as per your recommendation.
check your plugin module's settings, most probably the path to the plugin.xml to use is broken
-Xmx256m should be enough to start your plugin
You are absolutely right! I had multiple plugin.xml files even without noticing it. IntelliJ generates them when you change that path in the modules settings. I was even editing the wrong plugin.xml. Thanks a lot for you help so far.
Now I reach the code that does the actual registration of the xml schema file but unfortunately it does not seem to load because the schema is not available in code completion later on. This is my code:
public void registerResources(ResourceRegistrar resourceRegistrar) {
System.out.println("minilauncher register resources");
resourceRegistrar.addStdResource("http://www.bindows.net/Schema/3.0/", "BindowsAdfSchema.xsd", MiniLauncherComponent.class);
}
I do get the println in the console so thats good. The BindowsAdfSchema.xsd file is located in the same dir/package as the SchemaResources class itself (but MinLauncherComponent is in a different package). In the idea.log I can see that it couldnt find the resource:
pl.ExternalResourceManagerImpl - Cannot find standard resource. filename:BindowsAdfSchema.xsd klass=class com.segerfeldt.minilauncher.schemas.SchemaResources
How should I reference the file correctly to get it to load.
You must use FQN classpath resource notation, e.g. "/com/package/schema.xsd" where schema.xsd is located in this package
It wooorks!
For anyone else reading this, don't forget to add ;?*.xsd in the compiler settings or the xsd file won't be outputted to the jar.
I had done this but it took me half an hour to figure out that I had neglected the semicolon in there. Anyway, it works now.
Thanks a lot for you help Yann.