Adding Java packages to GWT

前端 未结 2 995
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 11:30

I\'ve tried searching but couldn\'t come up with a defined way on how to add your own packages to a GWT project.

My tree structure looks like this:

-com.         


        
相关标签:
2条回答
  • 2021-02-08 12:22

    You can get rid of the two source path lines, because by default GWT will pick up anything that is relative to the root, and in the client package like you have. You also need to move your gui package into your client package, so it would become:

    -com.mycompany
      -public
        MyApplication.html
      MyApplication.gwt.xml
    
    
    -com.mycompany.client
      MyApp.java
    
    -com.mycompany.client.gui
      TableLayout.java
    
    
    <module>
      <inherits name="com.google.gwt.user.User" />
      <entry-point class="com.mycompany.client.MyApp" />
    </module>
    

    Assuming your MyApp.java is an actual EntryPoint, then this should work just fine.

    One other thing to note is that you cannot use java classes that are not part of the GWT JRE Emulation library, and your project won't compile if you do. You should get very specific errors about this though. For example you cannot use library classes like java.math.BigDecimal, if they are not emulated. All of your own classes you create can be used though.

    0 讨论(0)
  • 2021-02-08 12:23

    even though, as @rustyshelf pointed out, gwt will convert everything that is under client.* automatically, there will be times when you will want to keep things outside of your client packages (reusing them in several project might be one of them) and for that the solution still resides in adding other packages to the process using the source element.

    now there is a trick, you have to decide whether you want to move the gwt.xml config file or whether you need to create a new one.

    for your case in particular (where both packages share a root in the package, com.mycompany) you can just move the <project_name>.gwt.xml file to the top most common package and just add the new package as a source (and keeping the <source path="client"/> there as well) thus making your file to look like:

    <source path="client"/>
    <source path="gui"/>
    

    on the other hand if the packages don't share any root, just create a new *.gwt.xml file with only the source elements and place it on a parent package to the sub-package you want to add, i.e:

    <module>
       <source path=""/>
    </module>
    

    note that if you need to give compilation-access to nested sub-packages do so by separating them with a / like in "admin/client"

    hope this help you get back on track and organize your code the best way possible.

    0 讨论(0)
提交回复
热议问题