Importing a Java Project in a PlayN Project - Lebby/ForScene GitHub Wiki

We have two projects:

Project 1: PlayNGenerated

Project 2: JavaLibrary

We need to use JavaLibrary project ( writed in java ) in a PlayN Project ( PlayNGenerated project ).

To simplify instruction we start to talk about Project 2 "JavaLibrary"

##Project 2: JavaLibrary

2.1 Create your maven project called JavaLibrary ( i suggest to use maven quickstart archetype, or if you are maven skilled ...choose your best solution ! :)

2.2 Structure your JavaLibrary tree package as follow:

com.something.javalibrary
com.something.javalibrary.abc.dev
com.something.javalibrary.xyz.ghi

NOTE 1: If you use external libraries, their sources must be available and must have a GWT.xml file.

NOTE 2: I suggest to DON'T put any file under javalibrary. Your class must be in subpackage then under abc, xyz,kim, etc. In javalibrary you must have ONLY JavaLibrary.gwt.xml and subdir.

2.3 Now you must define you GWT file in com.something.javalibrary Our file is called ... JavaLibrary.gwt.xml ... So If You project has a package tree like;

com.something.javalibrary
|- abc
|  |-dev
|- xyz
|  |-ghi
...
|- etc

You must put your GWT file under com.something.javalibrary. If your GWT filename is JavaLibrary you have :

PACKAGE.NAMEGWTFILE =  com.something.javalibrary.JavaLibrary.gwt.xml ( com.something.javalibrary/JavaLibrary.gwt.xml )

JavaLibrary.gwt.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='javalibrary'>
      <inherits name='com.google.gwt.user.User' />
      <!-- Specify the paths for translatable code                    -->
      <source path='abc'/>
      <source path='xyz'/>
...
      <source path='etc'/>
</module>

2.4 Modify your POM!: Add following lines to your POM.XML

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

or ( refered to PlayN 1.3.1 pom ):

<build>
    <resources>
      <resource>
        <directory>${basedir}/src</directory>
      </resource>
    </resources>
</build>

( it adds sources and gwt.xml files to jar that maven will build )

(What are we doing? ... something like this: http://mojo.codehaus.org/gwt-maven-plugin/user-guide/library.html ... obvious version ultra-redux ) Note: I simplify all, if you want more information i suggest to follow GWT Official Documentation.

IGNORE FOLLOWING CODE AND JUMP ON "Project 1: PlayNGenerated"

I Noticed PlayN developer changed pom architecture ... I'm inspecting ... pls ignore following code ... it's my "notepad", you can continue from step "Project 1: PlayNGenerated"

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
      </plugin>
    </plugins>

    <resources>
      <!-- include the source files in our main jar for use by GWT -->
      <resource>
        <directory>${project.build.sourceDirectory}</directory>
      </resource>
      <!-- and continue to include our standard resources -->
      <resource>
        <directory>${basedir}/src/main/resources</directory>
      </resource>
    </resources>
  </build>

Now, if your code is correct and maven is configured well ... this project is done. ( how i can test? see 1,3 ... )

Project 1: PlayNGenerated

1.1 I suppose you are able to run PlayN showcase and add a maven dependency

1.2 Create PlayNGenerated by PlayN Archetype ( pls use version 1.1.1 ... 1.2 is still buggy )

1.3 COMPILE & INSTALL PROJECT 2(JavaLibrary): mvn clean, mvn build, mvn install ( on JavaLibrary pom.xml path )

1.3.a Verify jar package: you'll find in your maven local repository, then open it by a zip/rar/jar compressor/decompressor

1.3.b Check jar package it must include gwt.xml file. Check your packages. It could be:

javalibrary
javalibrary.xyz .. etc

Your GWT file could be in javalibrary then javalibrary.Javalibrary.gwt.xml

1.4 Add Dependency in Project1 : Go in you PlayNGenerated-core pom.xml ( attention ,,, not in main but in core! ) and add your mvn project (JavaLibrary , compile , jar )

When you create a PlayN project using archetype, maven create all tree configuring all. If you need to use your external project in playn, you must add dependency in *-core.

1.5 Use your library in core

1.6 Modify PlayGenerated-html project: Find "GameName".gwt.xml then add:

<inherits name='javalibrary.JavaLibrary' />

( use 1.3.b to be sure!!!! )

PlayN use GWT compiler to translate all java code to html5/js, but it needs all source of your code. Basically you must do 2 step: a) Modify .gwt.xml of your archetype based project: ( insert ) ( this step 1.6) b) Create PACKAGE,gwt,xml in your project. You must specify all your source dir by ( step 2.3 )

1.7 Run & test ( mvn compile, ant run-html )

You can run using maven or ant. you can test html by using firefox + firebug console + use PlayN.log.debug() in your core Firebug console: you must install firebug plugin, activate firebug before you browse your html page, ( or simply activate and refresh :) ) and activate "persistent/inspect option" tab in firebug mode: all.

Note: if you're using eclipse i can give you some tips. If you modify Project 2, you must run mvn clean, mvn install, then update dependency on PlayNGenerated.

⚠️ **GitHub.com Fallback** ⚠️