Visar inlägg med etikett Flexible Environment. Visa alla inlägg
Visar inlägg med etikett Flexible Environment. Visa alla inlägg

2016-09-01

Scala Stack with Google Flexible Environment

Scala Stack with Google Flexible Environment

(this article is not yet completed)
(updated 2016-11-11)

I've created a few Maven projects based on Google Flexible Environment and Scala backend which produces HTML, CSS and JavaScript without any files (.html, .css, .sass, .less, .js) and without any frontend builder like Gulp or Grunt.

Goal

To produce all frontend from Scala backend utilizing shared code and to be fully tested.

Infographic

Scala servlets creates HTML with CSS and JavaScript.
This is a graphic representation of how it works.
  • All code is written in Scala
  • Code may share
    • Resources
    • Validation
    • Routes
    • Logic
    • Translations and other data
    • Structure of
      • HTML
      • CSS
  • A servlet can read Scala JS source code and compile a JavaScript
    • This includes the shared code
  • A servlet can build HTML with CSS 
  • Other servlets can provide REST API and also use the shared code
  • All code can be unit tested and all code can be tested in the same test
This means that the Scala stack covers both frontend and backend.

Code

There is a repository called Scala Stack at Github. There is one branch for jQuery in development and one branch for Angular which is only started:
*Unfortunately I can't afford Google Compute Engine running 24/7 and was forced to shut them down. If Google Compute Engine would scale from 0 to minimize expense I could start them again.

Examples

I'm currently working on a example using jQuery (in progress) and one using Angular (started).
Note that Scala JS source is placed in webapp, an alternative could be resources



2016-07-12

Google Flexible Environment with Virtual Scala JS Compiler

Google Flexible Environment with Virtual Scala JS Compiler

After several months I managed to translate Scala JS Fiddle to Google Java Flexible Environment 

Goal

To create a project with Scala backend which generates JavaScript in a virtual compiler.

Live Demo

The live demo uses a Scala Servlet to generate HTML (Scala Tags) with a JavaScript. A second Scala Servlet is responding to "/javascript.js" and is using a virtual compiler to compile a String with simple Scala JS code to a JavaScript

Environment

It's a Maven project using Google Flexible "Compat" Environment which includes some App Engine features (not used) and Java 8 with Servlet API 3.1.

Source

Check out my Github

2016-06-21

Logging with Flexible Environment and Jetty

Logging with Flexible Environment and Jetty

Problem

Logging was not available for Google Flexible Environment with Java 8 and Jetty 9. But after reading Jetty documentation all needed was added SLF4J as dependency and use it's Logger.

Solution

Add SL4FJ as dependencies in pom:

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.21</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.21</version>
    </dependency>

Use org.slf4j.LoggerFactory and org.slf4j.Logger to log:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static Logger logger = LoggerFactory.getLogger(JavaServlet.class);
logger.info("Info logging!");

Deployed

When deployed, the logging is shown in STDERR

2016-06-01

Flexible Environment with Scala

Flexible Environment with Scala

Started a new Maven project with Google's Flexible Environment including Java 8, Scala and Web Servlets 3.1.

Source code

You can find it here:
https://github.com/AIMMOTH/scala-js-compiler/tree/java8-scala-flexible-environment-web-servlet-3.1

2016-05-30

Uppdated! "Cannot determine the default location of the Google Cloud SDK" Solved

Error

Got a really annoying error while trying to run my local Flexible Environment with GCloud 
$ mvn -Dgcloud.gcloud_directory="c:\path\to\gcloud-sdk\" gcloud:run
[ERROR] Cannot determine the default location of the Google Cloud SDK.
[ERROR] If you need to install the Google Cloud SDK, follow the instructions located at https://cloud.google.com/appengine/docs/java/managed-vms
[ERROR] You can then set it via <gcloud_directory> </gcloud_directory> in the pom.xml
[ERROR]
org.apache.maven.plugin.MojoExecutionException: Unkown Google Cloud SDK location:C:\...\gcloud_sdk
        at com.google.appengine.gcloudapp.AbstractGcloudMojo.setupInitialCommands(AbstractGcloudMojo.java:170)
        at com.google.appengine.gcloudapp.GCloudAppRun.getCommand(GCloudAppRun.java:306)
        at com.google.appengine.gcloudapp.GCloudAppRun.execute(GCloudAppRun.java:292)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.441 s
[INFO] Finished at: 2016-05-30T20:21:34+02:00
[INFO] Final Memory: 24M/380M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.appengine:gcloud-maven-plugin:2.0.9.74.v20150814:run (default-cli) on project scala-js-compiler: Execution error: org.apache.maven.plugin.MojoExecutionException: Unkown Google Cloud SDK location:C:...\gcloud_sdk -> [Help 1]

Solution

It was much easier to solve! Just add Python to path (which is bundled in the Gcloud SDK).
But managed to use the locally installed python to run the python script which starts development server:
$ cd project
$ c:\...\gcloud_sdk\google-cloud-sdk\platform\bundledpython\python.exe c:\...\gcloud_sdk\google-cloud-sdk\bin\dev_appserver.py src\main\webapp