For a few weeks I've been trying out GWT. Now I want to integrate a new module i made in GWT with an existing Web application. My problem is that I wan t the module to be put in a subdirectory of the webapp. Currently the code is put in ${webappDirectory}, but I want it in ${webappDirectory}/protected.
Any thoughts?
GWT always compiles to a subfolder (named after the compiled module, or its rename-to attribute) of the -war folder you give it as argument; and it makes no assumption as to where the host page (the page that loads the *.nocache.js file) lives.
That means you can very well have your host page in a protected subfolder and have it load ../protected-gwt/protected-gwt.nocache.js.
If you really do want to put the compiled JS into the protected folder you'll have to either use it as the -war folder (and pass -deploy as argument to the GWT compiler pointing to the parent folder's WEB-INF/deploy –or somewhere else– if you don't want a protected/WEB-INF/deploy folder to be created), or move the files later, during your build process.
In any case, this will impact your ability to use the DevMode; one simple thing that's assured to work, is to deploy your webapp and launch the DevMode in -noserver mode.
Related
I'm doing some clean-ups in a GWT (no maven) project. It has a lot of jars added in WEB-INF/lib. I know the purpose of those jars (for example for REST service - luckily it's documented) so I wanted to put them in appropriate subfolders for nicer look.
After re-adding them to build path (as now they are in subfolders) I tried to run SuperDevMode and got multiple warnings:
Server class 'X' could not be found in the web app, but was found on the system classpath
and some errors like:
Cannot find a default implementation of the HK2 ServiceLocatorGenerator
When I put those jars back in WEB-INF/lib (without subfolders) and re-add to build path everything runs just fine.
My question is: can't/should't I use subfolders in WEB-INF/lib? If so, why?
Server class loader is programmed to look only into WEB-INF/lib, not other folder nor subfolders.
I strongly suggest to get into the maven world, it has a steep learning curve but it will assure to your project a solid foundation to grow on. Another big plus of Maven is that it can automatically pick up the latest security patch of your libraries (Equifax, anyone?).
Extract from the Apache Tomcat 7 Docs:
WebappX — A class loader is created for each web application that is deployed in a single Tomcat instance. All unpacked classes and resources in the /WEB-INF/classes directory of your web application, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application, are made visible to this web application, but not to other ones.
I am trying to use relative paths in a Dynamic Web Project in Eclipse. I am NOT using them in the Servlet, but in another class that is called by the Servlet. The file I am trying to access to is a property file located in
MyProject/WebContent/WEB-INF/propertyFile.properties
I have tried almost every relative path...
WebContent/WEB-INF/propertyFile.properties
/WebContent/WEB-INF/propertyFile.properties
./WebContent/WEB-INF/propertyFile.properties
MyProject/WebContent/WEB-INF/propertyFile.properties
/MyProject/WebContent/WEB-INF/propertyFile.properties
WEB-INF/propertyFile.properties
/WEB-INF/propertyFile.properties
./WEB-INF/propertyFile.properties
...and so on...what can I do?
Thanks in advance!
You nee to understand that file IO read files, from the filesystem, and relative to the directory from which the JVM (i.e. your web container) is started.
Remember that, once your app is deployed to production, there won't be any MyProject or WebContent folder. That's what exists on your development machine. The only thing that will exist in production is the war file deployed in the application server.
What you actually want is to load a resource, located in the deployed web application (i.e. which is inside your war file).
To do that, you must use ServletContext.getResourceAsStream():
InputStream in = servletContext.getResourceAsStream("/WEB-INF/propertyFile.properties");
I have created a GWT-loadable module (maven) with this output jar structure (using mvn package command):
mygwtlibrary
->src/main/java
-->org.mygwtlib
---->public
------>flash.swf
-->org.mygwtlib.client
---->MyClientCode.class
However when I run a application that use this library, error shows: Error 404 for fetching the flash.swf file.
Here's the scenario:
I have setup the project properly, including the <inherits> in the gwt.xml file
When I just include the whole library project into another GWT application project then run, it works fine. That is, the files from the public folder is loaded too.
What could be the problem?
The problem is that you're trying to fetch the flash.swf file over HTTP. This is (at best) bad practice. A better approach (by no means the only alternative) would be pulling it in as a resource which lives in your code. One way to do such a thing would be using Spring's ClassPathResource (or less preferably, FileSystemResource).
I have two modules, the Main module and the Included module.
If I start the Main module it will show an interface with an iFrame which contains the Included module with some additional controls around it. I can also start the Included module separately.
I have solved this by having two separate .gwt.xml files and two separate entrypoints and the result is then placed in the same war folder.
If I use GWT Compile in eclipse I can add both my entrypoints to the list and it will compile both modules and everything will work correctly.
However if I click the "Run" button in eclipse to have my application run in devmode, then it will only recompile the entrypoint that I access in my browser. If I access the Main entrypoint then I will get a popup saying "gwt module may need to be recompiled" and devmode will not automatically recompile my Include entrypoint.
Is there someway that I can get devmode in eclipse to -always- recompile all of my modules?
As I understand it, you use an IFrame that contains the host page of a secondary GWT module. This frame's content must also be loaded using the gwt.codesvr=127.0.0.1:9997 parameter, or it would just load the latest compiled version of the GWT javascript without using the devmode server.
You should also make sure the debug configuration in Eclipse contains both modules. You can verify that by not clicking the button directly, but using the menu to open the "Debug Configurations" menu. Assuming you clicked on the "Debug" button before, you should find an existing GWT debug configuration there. Make sure that both modules are listed in the "GWT" tab.
If you have your modules in two different projects, you might have to use two instances of the dev mode server. (remember to use different ports)
Add you included module to your main module.
You can do this by adding
<inherits name="fully qualified name of your module"/>
this code in your main.gwt.xml file.
I would contend that this is more of a "project setup" problem, than "how can I get Eclipse to compile all my modules" problem. The reason I say this is, I have yet to see a GWT project where two entry points were necessary/made sense. The main reason to have separate entry points is for reuse (Dev Guide, Dividing code into multiple modules).
The way I would approach the problem is to have your Main module, which includes the controls and iFrame (and have it inherit your Included module), so the same as you are now. Where I would differ is I would set up the Included module to not have an entry point. Instead, if you have a reason to run it separately from the Main module, I would create a "drive"/"launcher" module that also inherits the Included module. However, instead of controls and an iFrame like the Main module, this driver module would consist merely of an entry point and a place to attach your Included module.
You might also check out this question for more discussion in this same vein: Multiple Entry Points in GWT.
I'm using MEF to add plugins to our DAL which is used by our WebApp. This works fine, but when our service layer references the DAL, it's looking for plugins in \ServiceLayer\Plugins\
rather than \WebSite\Plugins\ (which makes sense are we're using a relative path. {DirectoryCatalog (Path="plugins/")}.
The problem is if we use an absolute path it refuses to load the plugins from both the SL and the DAL, which I believe is because the path isn't within the same directory or subdiectory of the App loading the plugins(?). How can I get them to both load plugins from one folder?
Thanks
You can't actually do this. Solution was to have a copy of the DLLs, one set in the web app folder, another in the service layer folder