Tuesday, March 21, 2017

Re: Maven/GWT: include sources in jar with relative path?



On Tuesday, March 21, 2017 at 5:27:18 PM UTC+1, Magnus wrote:
Hello,

when making java libraries containing GWT code, you have to include the sources in the jar file.
I do this in my maven project like this:

<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
    </resource>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.java</include>
        <include>**/*.gwt.xml</include>
      </includes>
    </resource>
  </resources>
</build>

This includes everything under src/main/java.
And everything that we include is relative to this path.
In my case, this is for example:

serverstuff/Database.java
serverstuff/Files.java
clientstuff/MyDialog.java
clientstuff/MyWindow.java

Now I would like to include only a subdirectory, say src/main/java/clientstuff.
To achieve this, I could change the directory tag above into

<directory>src/main/java/clientstuff</directory>

But then, also the origin of the paths in the resulting jar file changes.
The jar file will contain:
MyDialog.java
MyWindow.java
These are the classes that I want, but with a wrong path.
I want my jar file to contain:
clientstuff/MyDialog.java
clientstuff/MyWindow.java 
How can I do that?

Don't change your <directory>, play with the <includes> instead:

     <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>clientstuff/**/*.java</include>
        <include>clientstuff/**/*.gwt.xml</include>
      </includes>
    </resource>

Technically, you could instead add targetPath to relocate the files, but the former above feels cleaner IMO:

    <resource>
      <directory>src/main/java/clientstuff</directory>
      <targetPath>clientstuff</targetPath>
      <includes>
        <include>**/*.java</include>
        <include>**/*.gwt.xml</include>
      </includes>
    </resource>

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment