Packaging GWT module jar - gwt

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).

Related

Manifest.MF vs libraries.xml vs deployment.xml

So I am having issues deploying code to my local websphere server (imagine the dred I have for installing it to my test server).
I get a java.lang.ClassNotFoundException when I attempt to run the application.
So after googling around it seems as though I need to add entries into one of the above files. Problem is, there doesn't seem to be good examples of how to do that.
In the Manifest.mf file, do I need to add the fullpath to where I expect the jar to be? Does anybody have a good example of a deployment.xml/libraries.xml? How do I translate what is in my project classpath to entries into those various files?
Start with 'Websphere Class Loaders'.
Usually the order to load/find a class/resource is :
Current Module(war/jar/sar) --> (if not found then look inside) -->
Another Module in EAR (via manifest.mf) --> (if not found then try to load it from) -->
Common shared library (libraries.xml) (or) Extensions library -->
(if not found, then throw the error Class not found/No class Def found error).
Manifest.mf
Using this file you could point to the module/location directly to load the required classes/resources.
libraries.xml
Here you can define and maintain the shared libraries which can be used across many JVM's (like single jar file can be referenced from multiple jvm instances). Refer this for more information.
In my experience, I try to avoid using manifest.mf files, and refer the library jar files from shared library 'libraries.xml' file. (or) if you are trying to learn the Web sphare, then just include the jar files in lib/ folder of your package.

Creating Java library file with IntelliJ IDEA

I'm trying to create a library which could be used in other projects. I've written one class with several static methods to do some stuff. I wanted to try it out but I am not able to use the imported JAR file.
I have compiled my code as an artifact and took the JAR file from "out" folder and then copied it to another project. After that I went to "Project structure", tab "Libraries" and I pressed the plus button. I've found the JAR file and selected it, afterwards IDEA asked me to specify dependencies so I did, but when I want to use it in code I am not able to do so. It can't even be imported.
Any ideas why it ignores my library? Thanks!
What should I do in order to create a JAR library with IntelliJ IDEA, that is usable in other projects?
You are running into a very common dependency management problem.
IMO the real answer is to use a build system like Maven, Ant, or Gradle (I'd go Gradle myself). What you are trying to do is manual, hard to reproduce, and brittle.
Every time you make a change you will have to go through manual steps to create a new JAR. And you really don't understand your dependencies.
To go all out with best practices you would be to have real build system that publishes to a continuous integration server, which compiles and runs tests. On successful completion of the tests, the JARs are published to an artifact server (Nexus/Artifactory).
The people you are sharing with would consume the JARs via the build system by declaring dependencies on your JAR.
I figured out what my problem was. When I created the library I was trying to make it simple. Too simple, unfortunately. I had a package with a class in it that was compiled into a JAR. Structure shown below:
foo
|
|_ MyLib.java
However in order to use classes from a created JAR library they have to be placed in packages. That means if I have:
foo
|
|_bar
| |
| |_MyInnerLib.java
|
|_MyOuterLib.java
I am able to import and use methods from MyInnerLib but MyOuterLib isn't reachable nor importable. This was the error I was making.

Import directory structure into eclipse

I've recently gotten the source code to a jsp application (I'm primarily a c# guy, so apologies for any terminology that doesn't fit). I'm trying to use Eclipse to make changes and run the application locally, but am having some problems getting started.
The folder structure is as follows
/Admin
/css
/js
/jsp
...more folders that look like your typical web site
/WEB-INF
/classes
/lib
web.xml
taglib-i18n.tld
build.xml
index.jsp
I've tried creating an empty dynamic web application and dragging the folders in, but there are ton's of build errors saying that the code found in the sub directories under /classes/ isn't recognized.
I can run a very simple jsp tutorial locally, so I'm confident that tomcat and the jsp framework is installed.
The source code is coming straight from (sorry) Source Safe and the current methodology is to make changes and deploy and test on a development server.
Is there something obvious that I'm missing or need to configure?
Sounds like you are not telling Eclipse about your dependencies. Go to Project > Properties > Java Build Path > Libraries and make sure you have all your dependency JARs referenced there.

Fail to create custom UI component in ZK framework

Trying to create custom UI component going through ZK 6.0.1 Component Development Essentials.
Always got error in logs "http://localhost:8080/zk6/zkau/web/_zv2011051111/js/examples.com.foo.wpd : HTTP Status 404 - /js/examples.com.foo.wpd" when trying to use custom component.
Found the war file with this example in scala, it works OK. I have copied all files from it to my project, and got same error.
The project structure is according to tutorial. What might be wrong?
You have to put the web folder, which contains the js files, in the java classpath, that means it should be put under the src folder. More easy way is to use the ZK Maven Archetype to create the template for you.
At least the way IntelliJ IDEA does things (which I see your are using, as am I), simply placing the web folder under the src folder doesn't seem to automatically get it copied to the artifact (although I'm not sure why). So I tried manually putting it in the WEB-INF/classes folder, and that worked. So the correct path for your example is <project-root>/web/WEB-INF/classes/web/js/examples/com/foo/zk.wpd.

JUnit testing gwt web app with 2 modules

I am currently using gwt 2.3 and smartgwtpower 2.5 nightly and using Eclipse on Linux. My web app is using common code, developed in house, and packaged to a jar called commonsmartgwt.jar. In this jar is the entry point class and has its own gwt.xml file. In my web app's gwt.xml file I inherit from the entry point class
<inherits
name="common.code.Common"/>
and I use the entry point common.code.client.Common as my web app's entry point. All my classes in my web app extend classes in the common code. Compilation and running works
fine but when I try to run a test using eclipse method Run As > GWT Junit Test, I get the following error.
Unable to find common/code/Common.gwt.xml on your classpath; could be a typo,
or maybe you forgot to include a classpath entry for source.
If I create the folder common/code/ under classes and extract the .gwt.xml file from the commonsmartgwt.jar and put it in that directory, I get a different error.
'my.package.client.MyFirstTest' was not found in module
'common.client.Common'; no compilation unit for that type was seen
Is there a way to Unit test this application. Please let me know if my situation is not clear. What if I moved the entry point from the common code to my web app? I tried following the instructions here: [Error resolution][1]
[1]: http://raibledesigns.com/rd/entry/testing_gwt_applications "Link"
but this did not work.
I had the incorrect module name returning in the getModuleName test method.