- Define namespace where you want to create your linker. You do not need to use the client namespace, for example I use com.gwt2go.dev.linker to create my linker example.
- Create a class which implements AbstractLinker or just Linker from the namespace com.google.gwt.core.ext.linker. Personally after some investigations, I prefer to use the AbstractLinker class. It gives you access to methods to like the emit functions, which you can use into your code, we will see how later.
- Set up the order using LinkerOrder. With this annotation you set up the execution priority. For example LinkerOrder.Order.Post means execute after the primary linker. You can also select the options Pre or Primary. Primary means that your linker will be executed instead of the primary linker.
- Create new module file <module>.gwt.xml inside the namespace where you create your linker class. You can use also another namespace but for me was more easier to use the same. You have to define your linker inside, I will show you later how to do it.
- Inherits the linker inside your main <module>.gwt.xml file
- Add the linker using the “<add-linker name="<linker_name>" />”
1 @LinkerOrder(LinkerOrder.Order.POST)
2 public class ManifestLinker extends AbstractLinker {
3
4 @Override
5 public String getDescription() {
6 return "Personal simple linker";
7 }
8
9 public ArtifactSet link(TreeLogger logger, LinkerContext context,
10 ArtifactSet artifacts) throws UnableToCompleteException {
11
12 // Create a new set of artifacts that we can modify and return.
13 ArtifactSet toReturn = new ArtifactSet(artifacts);
14
15 // Add a new artifact to the set that we're returning.
16 toReturn.add(emitString(logger, "Some simple text here",
17 "gwt2go.appcache"));
18
19 return toReturn;
20 }
21
22 }
23
Very simple linker but it is perfect just to start and see how it works. This simple linker just creates a file with the name “gwt2go.appcache” and puts inside the text “Some simple text here”.
The next step will be to create linker module file, into which you will register the linker. As shown in the screenshot above, I created a module with the name ManifestLinker.gwt.xml in the same folder where the linker class was created. Inside the module file you have to register the linker:
1 <module>
2
3 <define-linker name="manifest" class="com.gwt2go.dev.linker.ManifestLinker" />
4
5 </module>
This is a very important step, without this registration if you try to use the linker you will always get exception that the linker could not be compiled.
We finish with the registration we can try use the custom linker. To do so, open your application main module file and inherit it. In my case I had to inherit the linker my Gwt2Go.gwt.xml file following:
1 <inherits name="com.gwt2go.dev.linker.ManifestLinker" />
After you inherited from the linker you have to add the linker again in the same main module file like this:
1 <add-linker name="manifest" />
We have now everything we need to start with something more complicated. In the next article I will try to show you how to use this linker to generated the offline manifest cache file.
cheers
Hi,
ReplyDeleteI'm very interested in that matter and wanted to ask if there will be a sequel to this post, soon?
Or has this approach turned out to be a dead end?
Regards, Roman
Yes, I plan a new one and start to make some examples, unfortunately due to my too much travelings in the last weeks, I wasn't able to finish it. I will try to post the next one this week.
ReplyDeleteOK, Part 2 is release you can read it now here:
ReplyDeletehttp://webcentersuite.blogspot.com/2011/06/writing-gwt-linker-for-offline.html
hiiii....it's very intresting.
ReplyDeleteReally interesting
ReplyDeletebut i can't use it... i'm using grails + gwt (via gwt plugin)
and for this example to work i have to use the gwt-dev.jar (usually i use the gwt-user.jar) in my lib path...
and this have some conflict with other library
java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/xml/sax/SAXParseException"
and I can't solve it :-(
Hi Gabriele, unfortunately I never used this approach, I afraid I would not be able to help you with it.
ReplyDeleteVery good artical!
ReplyDeleteDoes code splitting work well with appcache?
Yu
should not be a problem, I think
ReplyDelete