Diary: From PlayN to ForScene: "A maven story" - Lebby/ForScene GitHub Wiki

This page is a "log history" page. After months of testing, troubleshooting, rewrites, interruptions, etc. I've decided to log all my experience here. Here i writed my last attempts with playn-forscene. Here you can read steps without deep explainations.

I want write all mine step to resync my project to newer version of PlayN ( actually 1.3.1 ) Previous version works ... but I do something wrong .... : update. In my scenario, update is a complex work, because i must manually setup maven configuration on each pom and fix dependecy. It was my big mistake! Now, i've decided to rebuild all my project, redo all my work and setup it to work with PlayN 1.3.1 If i success, i'll freeze PlayN dependency to this stage ( PlayN 1.3.1 dependency ).

1st Attempt: I tried to create a new one project to test if newer playn archetype works ... it doesn't, but i think i did something wrong so ...

2nd Attempt: I've decided to write each command to inspect and verify if i'm doing it right ... I think it's best way. Don't trust yourself, but you must trust to your log! I choose to go by terminal. I don't trust Eclipse ... it's evil! It promise to you an "easy and sexy way" to do complex achievement, but it is not true. Do not trust Eclipse! It's a good IDE, but you're more powerfull!

My goals are:

a) Create a test project from archetype that works

b) Use test project to understand and test "From Project to archetype" adding ForScene dependency and modification

c) If i success in b) i'll revert it in a archetype project that use PlayN and ForScene

d) If i fail ... i'll be rude!

GOALS A: Create a test project from archetype that works Following: http://code.google.com/p/playn/wiki/GettingStarted

1) I opened terminal

2) I chosed a path to install the test project ( test )

mkdir test

3) Creation of project:

cd test
mvn archetype:generate -DarchetypeGroupId=com.googlecode.playn -DarchetypeArtifactId=playn-archetype -DarchetypeVersion=1.3.1

4) Configure Maven Project

groupid: com.github.Lebby
artifactid: ForScene archetype
version: 1.0-SNAPSHOT
package: forscene
JavaGameClassName: Main

5) Testing main project:

cd ForScene\ archetype/
mvn test
Error: 'artifactId' with value 'ForScene archetype' does not match a valid id pattern

6) remove garbage

cd .. 
rm -r ForScene\ archetype/

7) redo step 3

8) Configure Maven Project

groupid: com.github.Lebby
artifactid: ForSceneArchetype
version: 1.0-SNAPSHOT
package: forscene
JavaGameClassName: Main

9) Testing main project:

cd ForSceneArchetype/
mvn test

-> SUCCESS

10) Testing Java:

cd java
mvn test

[ERROR] Failed to execute goal on project ForSceneArchetype-java: Could not resolve dependencies for project Lebby:ForSceneArchetype-java:jar:1.0-SNAPSHOT: Could not find artifact Lebby:ForSceneArchetype-core:jar:1.0-SNAPSHOT in forplay-legacy (http://forplay.googlecode.com/svn/mavenrepo) -> [Help 1]

--> First i must test(build) core?

Better execute mvn package on all!

**11) Packaging and installing **

cd ..
mvn package
mvn install

-> SUCCESS 12) Testing Java (Again):

cd java
mvn test

-> SUCCESS

13) Testing HTML

cd ..
cd html
mvn test
cd ..
mvn -Phtml integration-test

-> SUCCESS ... started jetty server.

I opened Firefox and verified: http://localhost:8080/ Ok. It works!

GOALS A: ACCOMPLISHED!

GOALS B: Use test project to understand and test "From Project to archetype" adding ForScene dependancy and modification

This is a complex task ... I want to try to trust following istruction:

http://johnjianfang.blogspot.it/2009/05/create-maven-archetype-from-existing.html

http://maven.apache.org/guides/mini/guide-creating-archetypes.html

First i want to setup project to work with ForScene ... I could remember all basic steps ... maybe. I'll use Eclipse to speed up these operations!

  1. Importing "test project" in eclipse ... Open eclipse ( indigo ) File-> Import -> Maven -> Existing maven project

Browse: Choosed my ForSceneArchetype dir select all, Next, it shows some "errors" with a "resolve later" green solution. It's ok!

Ok ... Import operation : SUCCESS

  1. Let's begin to modify all! -.-'

2.1) Add ForScene forscene.version property in main pom.xml ( and setting it to 1.0 ... current fake forscene version )

2.2) Add ForScene-core Dependency forscene-core version: ${forscene.version} on core pom.xml

<dependencies>
   <dependency>
    	<groupId>com.github.Lebby</groupId>
    	<artifactId>forscene-core</artifactId>
    	<version>${forscene.version}</version>
    </dependency>
</dependencies>

2.3) Modify HTML project : modify gwt.xml Adding path of ForScene-core source: <inherits name='forscene.ForScene'/>

https://github.com/Lebby/ForScene/wiki/Importing-a-Java-Project-in-a-PlayN-Project

2.4) Modify -core Main.java from:

public class Main implements Game {
  @Override
  public void init() {
    // create and add background image layer
    Image bgImage = assets().getImage("images/bg.png");
    ImageLayer bgLayer = graphics().createImageLayer(bgImage);
    graphics().rootLayer().add(bgLayer);
  }

  @Override
  public void paint(float alpha) {
    // the background automatically paints itself, so no need to do anything here!
  }

  @Override
  public void update(float delta) {
  }

  @Override
  public int updateRate() {
    return 25;
  }
}

to:

import forscene.core.LoopController.AbstractGame;
import forscene.core.entities.AbstractScene;
import forscene.core.util.GraphicFactory;

public class Main extends AbstractGame {

	@Override	
	  public int updateRate() {
	    return 25;
	  }

	  @Override
	  public void build() {
		  AbstractScene scene = new SimpleScene();
		  addScene(scene);
	  }
	  
	  class SimpleScene extends AbstractScene{
            @Override
	    public void build() {
            // create and add background image layer
              GraphicFactory.addImage("images/bg.png",this);					
	    }

	    @Override
	    public void updateState() {
	    // TODO Auto-generated method stub
	    }
	  }
}

2.5) Testing:

cd .. 
mvn package
mvn test -P java

OK ... it works!

  1. FROM Project to archetype testing phase ...

http://johnjianfang.blogspot.it/2009/05/create-maven-archetype-from-existing.html

http://maven.apache.org/guides/mini/guide-creating-archetypes.html

http://maven.apache.org/archetype/maven-archetype-plugin/advanced-usage.html

3.1) Create archetype

mvn archetype:create-from-project

There are 2 skipped that i don't like them ...

[INFO] Main Core ......................................... SKIPPED
[INFO] Main Android ...................................... SKIPPED

I'll skip too ...

Details:

[INFO] Archetype created in ".." ForSceneArchetype/target/generated-sources/archetype

3.2) Inspecting generated files

It works! But there are may thing to modify, like:

  • parametrization of main class -> i'll grab from PlayN Archetype; it's like __JavaClassName* ( if my memory records are right )
  • changes on package, groupId, artifactId of core ...

It's better than create a "clear" project for this purpose, adding dependency, recreate this archetype, add customization. I'm very lucky that all my previous step was logged by me!

So i can say that this GOAL is achieved!

c) Create of true Archetype I did all Goal A & B steps:

mvn archetype:generate -DarchetypeGroupId=com.googlecode.playn -DarchetypeArtifactId=playn-archetype -DarchetypeVersion=1.3.1

groupid: com.github.Lebby
artifactid: forscene
version: 1.0-SNAPSHOT
package: forscene
JavaGameClassName: Main

mvn test
mvn package
  • added forscene.version in pom.xml on root ( step B.2.1 )
  • added ForScene-core dependency in pom.xml -core subdir
  • added library in gwt.xml on -html project ( steb B.2.3 )
  • modified Main class in -core ( step B.2.4 )
  • archetype creation:
mvn archetype:create-from-project
cd target/generated-soruces/archetype
  • open PlayN archetype pom.xml
  • edit target/generated-soruces/archetype/pom.xml:
  • removed groupId, artifactId, version.
  • Added parent and artifactId correct information:
  <parent>
    <groupId>com.github.Lebby</groupId>
    <artifactId>forscene-project</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>forscene-archetype</artifactId>
  <name>ForScene Project Archetype</name>
  <description>Archetype for ForScene game projects ( based on PlayN ).</description>
  • deleted build and repository section and added this:
   <build>
    <extensions>
      <extension>
        <groupId>org.apache.maven.archetype</groupId>
        <artifactId>archetype-packaging</artifactId>
        <version>2.0</version>
      </extension>
    </extensions>

    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-archetype-plugin</artifactId>
          <version>2.0</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.5</version>
          <configuration>
            <escapeString>\</escapeString>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>archetype-resources/pom.xml</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <excludes>
          <exclude>archetype-resources/pom.xml</exclude>
        </excludes>
      </resource>
    </resources>
  </build>
  • opened PlayN archetype pom.xml in archetype/src/main/resources/archetype-resources
  • edited ForScene archetype pom.xml in archetype/src/main/resources/archetype-resources:
  <parent>
    <groupId>com.github.Lebby</groupId>
    <artifactId>forscene-project</artifactId>
    <version>${project.version}</version>
  </parent>

  <groupId>\${groupId}</groupId>
  <artifactId>\${artifactId}</artifactId>
  <version>\${version}</version>
  <packaging>pom</packaging>
  <name>\${JavaGameClassName} Metaproject</name>

  <properties>
    <playn.version>${project.version}</playn.version>
    <forscene.version>${project.version}</forscene.version>
  </properties>
  • copied java dir from PlayN archetype to forscene archetype ( i don't kwnow why it is missed ... )
  • REMEMBER: MUST VERIFY ALL OTHER DIR!
  • modified ForScene build.xml. ( templating name class )
<project name="${rootArtifactId}" default="run-java" xmlns:artifact="urn:maven-artifact-ant">
  <!-- Define your project information here -->
  <property name="java.classname" value="${package}.java.${JavaGameClassName}Java"/>
  <property name="html.classname" value="${package}.${JavaGameClassName}"/>
  <property name="html.index" value="${JavaGameClassName}.html"/>
  • Checking -core. modified pom.xml
  <artifactId>${artifactId}</artifactId>
  <packaging>jar</packaging>
  <name>${JavaGameClassName} Core</name>

lol ... it depends on itself? :D. removed:

    <dependency>
      <groupId>${groupId}</groupId>
      <artifactId>${rootArtifactId}-core</artifactId>
      <version>${version}</version>
    </dependency>
  • renamed: Main.java in JavaGameClassName.java ( archetype-resources/core/src/main/java/core )
  • modified JavaGameClassName.java:
package ${package}.core;

import static playn.core.PlayN.*;

import forscene.core.LoopController.AbstractGame;
import forscene.core.entities.AbstractScene;
import forscene.core.util.GraphicFactory;
  • inspected others pom so i decided to delete all generated dir and copy all from playN archetype
⚠️ **GitHub.com Fallback** ⚠️