Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

[GAE] How to create GWT project updated by Gradle for GAE on Eclipse

This is a stretch for the memo right now and it will be enhanced with photo or video later.

1. Create a GWT project by GWT plugin
2. Right click on the project -> Configure -> Convert to App Engine Standard Project
3. Right click on the project -> Configure -> Add Gradle Nature
4. Create text file named build.gradle file under project folder.
5. Write the configuration of this project in build.gradle.
   For example:

//This section used for classpath setup
def ROOT_PATH = '{{ root_path_of_project }}'
def LIBS_PATH = ROOT_PATH + '{{ root_path_of_lib }}'
def MODULE_PATH = ROOT_PATH + '{{ root_path_of_module }}'

//Uncomment this field when trying to fetch the latest version of libraries.
apply plugin: 'java'
apply plugin: 'gwt'
apply plugin: 'eclipse'
apply plugin: 'war'

//Script version
version = '1.0'

//this concept is used to define the external dependencies that are available to the classloader 
//during the execution of Gradle build script. In the declaration of dependencies only be used 
//the method classpath, and you can’t use the configurations compile , runtime, testCompile, etc. 
//because this block is just to declare external libraries references available to the classpath, 
//if you need to provide any configuration like compile or runtime you need to do outside of BuildScript block.
buildscript{
 repositories {
  //The repository where to fetch gwt gradle plugin
  jcenter()
  
//  maven {
//            url 'http://dl.bintray.com/steffenschaefer/maven'
//        }
 }
 
 dependencies {
  //0.6
  classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
 }
}


//Central repository to load the GWT library
//indicates where Gradle looks for any required dependency, in this case in the Maven central repository. 
//For this example get gwt libraries and automatically fetch gwt dependencies; 
//while the script is executing some lines like these appears in the console.
repositories{
 mavenCentral()
}

eclipse{
 //To setup output classess folder for gwt project
 classpath{
  defaultOutputDir=file("war/WEB-INF/classes")
 }
/*
 project{
  //To setup linked resource folder
  linkedResource name:'{{ name_of_linked_ref }}', type:'2', location: LIBS_PATH + '{{ path_of_linked_ref }}'
 }
 
    classpath {
        file {
            withXml {
                def node = it.asNode()
                node.appendNode('classpathentry', [kind: 'src', path: '{{ name_of_linked_ref }}', exported: true])
            }
        }
    }
*/ 
}

gwt{
 gwtVersion='2.8.1'
 modules 'com.digsarustudio.qbox.QBox'
 
 sourceSets{
  main{
   java {
    srcDir 'src'
   }
  }
  
  test{
   java {
    srcDir 'test'
   }
  }  
 }
 
 logLevel = 'INFO'
 
 minHeapSize = "512M"
 maxHeapSize = "1024M"
 
 superDev{
  noPrecompile=true
 }
 
}

dependencies {
 //google cloud sql factory - This is very important for the project which uses Cloud SQL as the database.
/* 
 compile 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.0.10'
*/ 
 compile 'com.google.cloud.sql:mysql-socket-factory:1.0.9'
 
 //Google Gruava - For Cloud SQL MySQL Socket Factory
 compile 'com.google.guava:guava:26.0-jre'

  //[Optional] For NoClassDefFoundError while including MySQL Socket Factory Connector
  compile group: 'org.ow2.asm', name: 'asm', version: '5.2'
}


6. Right click -> Gradle -> Refresh Gradle Project(This will break the GAE project structure)
7. Reorganise the structure of folders to meet the GWT requirements
8. Copy the customised or 3rd party libraries under /war/WEB-INF/lib
9. Change the .level FROM WARNING to INFO in the logging.properties file if you want to see the INFO log in the logger.
10. Add <load-on-startup>1</load-on-startup> under a required servlet tag in the web.xml and <warmup-requests-enabled>true</warmup-requests-enabled> into appengine-web.xml if you need this servlet has to been initialised when this app starts up.

That's it. The next section will show how to deploy this GWT project upto the Google App Engine.

Coming soon:
 1. How to make GWT project to use Cloud SQL in Java 8
 2. How to skip the file amount limitation of a GWT project which is going to upload to Google App Engine.
 3. How to initialise configuration of Web App when the app starts up.

Note:
 For point 6:
     After refresh the project, Gradle will reset the content of "{{ project_folder }}/.settings/org.eclipse.wst.common.component". This leads to that Eclipse cannot deploy the GAE project due to the appengine-web.xml cannot be found. The plugins will go through {{ project_folder }}/WEB-INF to look for it. However, WEB-INF is under {{ project_folder }}/war for GWT. To fix this issues, please place the following text of section in to this file:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="{{ project_name }}">
   <wb-resource deploy-path="/" source-path="/war" tag="defaultRootSource" />
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/test"/>
   
   <property name="context-root" value="{{ project_name }}"/>
   <property name="java-output-path" value="/{{ project_name }}/war/WEB-INF/classes" />
  </wb-module>
</project-modules>

[GWT]How to use Google Web Toolkits - Installation

GWT version: 4.4
Eclipse version: 4.4 (Luna)
Java version: 1.7
OS: Mac OS X 10.10.1

  First of all, "Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based application." The purpose of this toolkit is to make possible productive development of high-performance web applications without the developer having to be an expert in browser quirks, XMLHttpRequest, and JavaScript. It's open source and completely free as well. In this toolkit, it contains SDK and Plugin for Eclipse so that we can use Eclipse as the editor to develop web application we want. The steps of installation will be illustrated as follows.

  1.Setup Eclipse:
     Downloading Eclipse from official website. Normally, I will choose Eclipse IDE for Java EE Developers as my IDE because I prefer to use this tool to develop C or C++ on Mac. Extracting zip file directly when the downloading finished.

  2.Get Plugin for Eclipse (including SDKs)
        There are two ways to get Plugin for Eclipse, one is downloading from download page of GWT, another one is installing Google Plugin for Eclipse via a link such as http://dl.google.com/eclipse/plugin/x.x. The "x.x" is the version of Eclipse, such as 4.3 for Kepler and 4.4 for Luna. According to the user guide of configuration Eclipse, we need to use Install dialog to install this plugin. The steps of installation are as following:

    I. To choose "Install New Software".

    II. Checking "Google Plugin for Eclipse(required)" and clicking "Next" button to complete the installation.

    The Eclipse needs to be restarted after installation. When the Eclipse restarted, we can use it for developing web application with GWT.

[Eclipse]新建立的Android專案出現"R cannot be resolved to a variable"

這問題其實是很詭異的,因為同樣是今年,只是在SDK是使用r20以前的時候,都可以正常建立新專案(這時的Target SDK為2.3.3)。但今天把它更新到r22.0後,就出現了標題所列的問題。

找了很多網路資料,不管是Clean後又Build,還是專案重建,都一樣的結果。

後來找到這篇「Android: r cannot be resolved to a variable」 ,他有提到是因為SDK4.x的專案建立的時候,會在res底下多出了value-v11以及value-v14這兩個資料夾。然後這個時候設定的Minimun Required SDK是設定為2.3.3。所以根據那篇的說法,這樣2.3.3的SDK是不認識那兩個資料夾,所以就變得無法產生R.java。

後來專案刪掉後重建的時候,把Minimun Required SDK選擇成4.2,就正常可以產生R.java了。

後來又為了要確認問題,所以把Minimun Required SDK、Target SDK、以及Compile With都設定為2.3.3。嘿嘿,好玩了,建立出來的專案一樣不能產生R.java。

所以這意思是,SDK Tools用了r22以後的,就不能編譯給2.3.3用的APP嚕?

後記:
結果打完這篇之後,建出來的專案又不正常了。
之後又找了其他參考,有人指出是需要Android SDK Build-tools。所以在更新這個tools之後,r就一切都正常了。


然後如果Unity還在用3.5.7以下的話,Android SDK Platform-tools請不要更新,不然會發生Unity無法編譯apk的慘劇。唯一的解決辦法就是把,Android SDK Platform-tools降版本至16.0.2以下,以及不要安裝Android SDK Build-tools。

(2013/06/27 - 目前確認,造成Unity無法編譯的是Android SDK Build-tools,僅需把Android SDK Build-tools移除掉,Unity就可以正常編譯了。)

[Eclipse]安裝Android Develop Tools

關於Elipse安裝ADT的教學,在Google上還蠻多的。但為了自己找資料方便,所以就乾脆自己寫一份,這樣之後忘記的時候,還有的地方可以找。

1.選擇Help->Install New Software。



 2.在「Work with:」處,輸入http://dl-ssl.google.com/android/eclipse/site.xml後。
    在這邊可以按下Add,把這個路徑加到「Available Software Sites」裡,以方便之後的更新使用。


3.在輸入完路徑之後,Eclipse的Installer就會開始向遠端主機取得相關的軟體資訊。這邊目前沒有研究個個項目的功能,所以就一併都下載了。(網路上的教學大部分都只說下載前兩項即可)


 4.確認項目是否正確,一樣就按「Next」即可。

5.按下接受授權項目。

6.下載中...

8.下載完成後,會選擇Andorid SDK的取得方式。由於之前為了Unity已經有獨立安裝Android SDK了,所以這邊就選擇已經存在的SDK的資料夾。如先前沒安裝過的,就可以選「Install new SDK」。

就這樣,Android ADT就裝好了。接下來就看要自己要玩些什麼嚕。

Build docker image from multiple build contexts

Build docker image from multiple build contexts ...