I'm new to GWT, but already has created some simple web applications
using this technology.
I need to have an ability to add to my GWT project some my extra java
sources.
I want to use in my GWT application this code:
/************************************************************/
public final class ClassForGWT {
public ClassForGWT() {
}
public String MyFunction()
{
return "my result";
}
}
/************************************************************/
This is not "pure GWT" class.
But I simply need to call "MyFunction()" from my GWT application.
(create class instance and call a method)
This is NOT widget at all.
I use NetBeans 5.0
How to do this "as simple as possible" ?
Please explain this operation step by step.
> The simplest way to do this is to copy the .java file into your client
> directory as a new class.
Yes! The simplest way - is just for me, so far :-)
And it WORKS!
Thank you!
But another, following up question: if I want use the same files with
my class(es) in a several projects, need I to copy these my *.java
files into each "client" directory ?
Or... is there another way to share this one file, without create many
copies of the one *.java class file ?
basically, this makes a module that contains your translatable
source, then you can just inherit that module in any new module you
want.
In each of your modules(gwt.xml files) that you need to use that
source, simply add the line:
<inherits name="com.me.Common" />
-jason
> so maybe have your code in com.me.trans.source
> then create the file
> com.me.Common.gwt.xml
> <module>
> <source path="trans/source"/>
> <module>
>
A little bit more explanation, about paths, please...
Actually, I have created a NetBeans' project, called "mygwttools" (my
extra code)
located: "c:\Java\Projects\mygwttools"
It is created like a package, so, after compile I have JAR,
located here: "c:\Java\Projects\mygwttools\dist\mygwttools.jar", but
don't mention it.
My sources are here: "c:\Java\Projects\mygwttools\src\mygwttools"
There are 3 files: gwtSQL.java, MD5.java, TProgressWindow.java
All files are error free, compilable and even includ-able in GWT
project,
like Dan Morrill told me above (copy them into my client directory as
a new class)
My GWT project names "polladmin",
and I have copied files to "c:\Java\Projects\polladmin\src
\GWTApplication\client"
This is works.
So, now, where I have to place (for example, of course) these my 3
files,
where I have to put "com.me.Common.gwt.xml" ? (and how to name this
file?)
What source-tag "<source path="..???..>" I need to create ?
Where to point "path" parameter ?
I understand, that "<inherits name="..." />" needs to be included in
my
GWT project's main XML file, now it is located here - "c:\Java\Projects
\polladm\src\GWTApplication\Main.gwt.xml"
After all, what path in "name" parameter I need to enter ?
By now my Main.gwt.xml looks like :
/******************************************/
<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.user.User"/>
<inherits name="mygwttools"/>
<source path="c:\Java\Projects\mygwttools\src\mygwttools"/>
<entry-point class="GWTApplication.client.Main"/>
</module>
/******************************************/
But it is NOT WORKS....
Just on your taste.
Please give a small sample for me, with paths.
Thnak you.
>
> OK!
>
>> so maybe have your code in com.me.trans.source
>> then create the file
>> com.me.Common.gwt.xml
>> <module>
>> <source path="trans/source"/>
>> <module>
>>
>
> A little bit more explanation, about paths, please...
>
> Actually, I have created a NetBeans' project, called "mygwttools" (my
> extra code)
> located: "c:\Java\Projects\mygwttools"
>
> It is created like a package, so, after compile I have JAR,
> located here: "c:\Java\Projects\mygwttools\dist\mygwttools.jar", but
> don't mention it.
Quick note, creating a jar with your gwttools code is a reasonable
thing to do, then you can just add that jar to your classpath in any
project in which you want to use the tools. HOWEVER, you have to
include the source files (.java) in the jar since the GWT compiler
works from source not from bytecode.
> My sources are here: "c:\Java\Projects\mygwttools\src\mygwttools"
> There are 3 files: gwtSQL.java, MD5.java, TProgressWindow.java
I would add a \client directory as well (I think GWT used to have
problems with the default package at one point), and put your files
there:
C:\Java\Projects\mygwttools\src\mygwttools\client\gwtSQL.java etc
then in mygwttools, create:
C:\Java\Projects\mygwttools\src\mygwttools\MyGWTTools.gwt.xml
Since your tools files are already in the .client package, your
Module (gwt.xml file) can be very simple:
<module>
<inherits name="com.google.gwt.user.User"/>
</module>
Then, when you create your jar file, create it with both the .class
files and the .java files (and the MyGWTTools.gwt.xml file) in their
proper path in the jar.
> All files are error free, compilable and even includ-able in GWT
> project,
> like Dan Morrill told me above (copy them into my client directory as
> a new class)
> My GWT project names "polladmin",
> and I have copied files to "c:\Java\Projects\polladmin\src
> \GWTApplication\client"
> This is works.
>
> So, now, where I have to place (for example, of course) these my 3
> files,
> where I have to put "com.me.Common.gwt.xml" ? (and how to name this
> file?)
> What source-tag "<source path="..???..>" I need to create ?
> Where to point "path" parameter ?
Since the step above puts the source in the xxx.client package, you
don't even need the <source> tag anymore. That is primarily for if
you don't want to follow the suggested package structure.
> I understand, that "<inherits name="..." />" needs to be included in
> my
> GWT project's main XML file, now it is located here - "c:\Java
> \Projects
> \polladm\src\GWTApplication\Main.gwt.xml"
>
> After all, what path in "name" parameter I need to enter ?
>
> By now my Main.gwt.xml looks like :
> /******************************************/
> <?xml version="1.0" encoding="UTF-8"?>
> <module>
> <inherits name="com.google.gwt.user.User"/>
> <inherits name="mygwttools"/>
> <source path="c:\Java\Projects\mygwttools\src\mygwttools"/>
> <entry-point class="GWTApplication.client.Main"/>
> </module>
> /******************************************/
Now, put your gwttools.jar file in the classpath (if you compile
using the generated scripts, you'll also need to add it to them.
and in your Main.gwt.xml just add
<inherits name="mygwttools.MyGWTTools"/>
Note: the inherits tag points to the fully qualified name of the
inherited gwt.xml file (minus the .gwt.xml extension)
This is basically the process used for importing the main GWT
libraries, and other third party libraries. so basically you are
creating your own third party library (mygwttools).
-jason
*******************************************************************
Loading module 'GWTApplication.Main'
Loading inherited module 'mygwttools.MyGWTTools'
[ERROR] Unable to find 'mygwttools/MyGWTTools.gwt.xml' on your
classpath; could be a typo, or maybe you forgot to include a classpath
entry for source?
*******************************************************************
Where this MyGWTTools.gwt.xml must be located ?
Here is a screenshot (11kb. GIF) - http://img209.imageshack.us/
img209/3062/myjarac4.gif
mygwttools.jar included in my project as usual and "inherits" is
mentioned
I have placed my JAR here: c:\Java\widgets\mygwttools.jar
and "c:\Java\widgets" is in SYSTEM'S (!!!) classpath variable.
I have put sources everywhere in my JAR -
see (3kb. GIF) - http://img215.imageshack.us/img215/7083/myjar2gp9.gif
But when I even put my "client" directory with sources inside JAR here
-
c:\Java\widgets\mygwttools.jar\mygwttools\client
and place here "c:\Java\widgets\mygwttools.jar\mygwttools
\MyGWTTools.gwt.xml" too
containing:
*************************************************
<module>
<inherits name="com.google.gwt.user.User"/>
<source path="client"/>
</module>
*************************************************
or without <source path="client"/>
compiler says:
--------------------
init:
deps-jar:
Analyzing source in module 'GWTApplication.Main'
[ERROR] Errors in 'jar:file:/C:/Java/widgets/mygwttools.jar!/
mygwttools/client/MD5.java'
[ERROR] Line 1: The declared package does not match the
expected package mygwttools.client
[ERROR] Errors in 'jar:file:/C:/Java/widgets/mygwttools.jar!/
mygwttools/client/TProgressWindow.java'
[ERROR] Line 1: The declared package does not match the
expected package mygwttools.client
[ERROR] Errors in 'jar:file:/C:/Java/widgets/mygwttools.jar!/
mygwttools/client/gwtSQL.java'
[ERROR] Line 1: The declared package does not match the
expected package mygwttools.client
What I'm doing wrong ???
This means that the GWTCompiler doesn't have that jar on its
classpath, or your jar doesn't have the gwt.xml file in the right
place. your jar should look something like:
mygwttools.jar
/mygwttools/MyGWTTools.gwt.xml
/mygwttools/client/gwtSQL.java
/mygwttools/client/gwtSQL.class
/mygwttools/client/MD5.java
/mygwttools/client/MD5.class
/mygwttools/client/TProgressWindow.java
/mygwttools/client/TProgressWindow.class
if that is correct, and the jar is on the classpath, then maybe
netbeans needs it on the sourcepath too (just grasping at straws here).
maybe someone with some netbeans experience could chime in.
-jason