2016年2月11日木曜日

Play! 2.4.4 + Scala 2.11.6 バイナリ、Jar、warファイルを生成する

  • このエントリーをはてなブックマークに追加


最近、Play 2.4.4 + Scala 2.11.6でプログラムを書いていて、アプリのデプロイ方法色々調べてたので、binary, jar, war ファイルの方法をご紹介します。

バイナリファイル

これは推奨されるやり方だそうです。javaさえインストールしていればそのまま実行できます。
構成ファイルbuild.sbtやplugin.sbtファイルに特別な設定入れなくても大丈夫です。
プロジェクトフォルダ(myApp)に入って、activator distを実行する
PS C:\myApp> .\activator dist
image_thumb3
これで. C:\myApp\target\universal\myapp-1.0-SNAPSHOT.zip ファイルが生成される。
zipファイルを解凍して、以下のようなフォルダ構造になります。
image_thumb5
bin フォルダの下に、2つの実行ファイルがあります。myappはLinux版、myapp.batはWindows版になります。
image_thumb7
ファイルを実行する
C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin> .\myapp 
デフォルトポート9000を他のポートに変更することもできます。
C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin> .\myapp “-Dhttp.port=8080”
※注意:ダブルクオーテーションが必要です。ない場合は、以下の様なエラーが表示される
PS C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin> .\myapp -Dhttp.port=80 Bad root server path: C:\myApp\target\universal\myapp-1.0-SNAPSHOT\bin\8080
image_thumb9

JARファイル

Jarを生成する場合は、sbt-assemblyプラグインが必要です。
build.sbtファイルに以下のコードを追記する。
//configuration for activator assembly : start
import AssemblyKeys._
assemblySettings
mainClass in assembly := Some("play.core.server.NettyServer")
fullClasspath in assembly += Attributed.blank(PlayKeys.playPackageAssets.value)
//skip test test in assembly := {}
jarName in assembly := "myApp.1.0-SNAPSHOT.jar"
mergeStrategy in assembly := {   case PathList("javax", "servlet", xs @ _*)         => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".properties" => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".xml" => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".types" => MergeStrategy.first   case PathList(ps @ _*) if ps.last endsWith ".class" => MergeStrategy.first   case "application.conf"                            => MergeStrategy.concat   case "unwanted.txt"                                => MergeStrategy.discard   case x =>     val oldStrategy = (mergeStrategy in assembly).value     oldStrategy(x) }
//configuration for activator assembly : end
......
project/plugins.sbtに以下を追記する
//configuration for activator assembly
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2") 
バージョンを0.11.2にしてますが、sbtのバージョンに合わせる必要です。以下をご参照ください。
https://github.com/sbt/sbt-assembly/tree/0.11.2

activator assemblyを実行する
PS C:\myApp> .\activator assembly[info] Loading project definition from C:\myApp\project
[info] Set current project to myApp (in build file:/C:/myApp/)
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript asse
ts compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] Including from cache: play-cache_2.11-2.4.6.jar
[info] Including from cache: xml-apis-1.4.01.jar
[info] Including from cache: ehcache-core.jar
[info] Including from cache: jta-1.1.jar
[info] Including from cache: play-ws_2.11-2.4.6.jar
[info] Including from cache: scala-library.jar
[info] Including from cache: guice.jar
[info] Including from cache: twirl-api_2.11.jar
[info] Including from cache: scala-reflect-2.11.6.jar
[info] Including from cache: jackson-core.jar
[info] Including from cache: commons-lang3.jar
[info] Including from cache: jackson-annotations.jar
[info] Including from cache: guava.jar
[info] Including from cache: javax.inject.jar
[info] Including from cache: aopalliance.jar
[info] Including from cache: jackson-databind.jar
[info] Including from cache: scala-xml_2.11-1.0.1.jar
[info] Including from cache: jackson-datatype-jdk8.jar
[info] Including from cache: play-server_2.11-2.4.6.jar
[info] Including from cache: async-http-client.jar
[info] Including from cache: signpost-core-1.2.1.2.jar
[info] Including from cache: guice-assistedinject.jar
[info] Including from cache: play_2.11-2.4.6.jar
[info] Including from cache: play-netty-server_2.11-2.4.6.jar
[info] Including from cache: netty.jar
[info] Including from cache: jackson-datatype-jsr310.jar
[info] Including from cache: build-link-2.4.6.jar
[info] Including from cache: play-exceptions-2.4.6.jar
[info] Including from cache: play-netty-utils-2.4.6.jar
[info] Including from cache: signpost-commonshttp4-1.2.1.2.jar
[info] Including from cache: slf4j-api.jar
[info] Including from cache: javassist.jar
[info] Including from cache: jul-to-slf4j.jar
[info] Including from cache: netty-http-pipelining.jar
[info] Including from cache: httpcore.jar
[info] Including from cache: play2-war-core-servlet30_2.11-1.4-beta1.jar
[info] Including from cache: play-iteratees_2.11-2.4.6.jar
[info] Including from cache: httpclient.jar
[info] Including from cache: play2-war-core-common_2.11-1.4-beta1.jar
[info] Including from cache: commons-logging-1.1.1.jar
[info] Including from cache: play-jdbc_2.11-2.4.6.jar
[info] Including from cache: scala-stm_2.11-0.7.jar
[info] Including from cache: play-jdbc-api_2.11-2.4.6.jar
[info] Including from cache: mariadb-java-client-1.3.4.jar
[info] Including from cache: jcl-over-slf4j.jar
[info] Including from cache: bonecp.jar
[info] Including from cache: config.jar
[info] Including from cache: HikariCP.jar
[info] Including from cache: scala-parser-combinators_2.11-1.0.1.jar
[info] Including from cache: anorm_2.11-2.4.0.jar
[info] Including from cache: play-json_2.11-2.4.6.jar
[info] Including from cache: anorm-tokenizer_2.11-2.4.0.jar
[info] Including from cache: h2.jar
[info] Including from cache: scala-arm_2.11-1.4.jar
[info] Including from cache: logback-core.jar
[info] Including from cache: tyrex.jar
[info] Including from cache: scala-continuations-library_2.11-1.0.1.jar
[info] Including from cache: play-functional_2.11-2.4.6.jar
[info] Including from cache: play-datacommons_2.11-2.4.6.jar
[info] Including from cache: logback-classic.jar
[info] Including from cache: bootstrap-3.3.1.jar
[info] Including from cache: joda-time.jar
[info] Including from cache: jquery-1.11.1.jar
[info] Including from cache: joda-convert.jar
[info] Including: myapp_2.11-1.0-SNAPSHOT-web-assets.jar
[info] Including from cache: akka-actor_2.11.jar
[info] Including from cache: akka-slf4j_2.11.jar
[info] Including from cache: commons-codec.jar
[info] Including from cache: xercesImpl-2.11.0.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF\DEPENDENCIES' with strategy 'discard'
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF\services\com.fasterxml.jackson.databind.Module' with strategy 'filterDistinctLines'
[warn] Merging 'META-INF\services\java.sql.Driver' with strategy 'filterDistinctLines'
[warn] Merging 'org\apache\commons\logging\Log.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\LogConfigurationException.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\LogFactory.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\NoOpLog.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\SimpleLog$1.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\SimpleLog.class' with strategy 'first'
[warn] Merging 'reference.conf' with strategy 'concat'
[warn] Strategy 'concat' was applied to a file
[warn] Strategy 'discard' was applied to 2 files
[warn] Strategy 'filterDistinctLines' was applied to 2 files
[warn] Strategy 'first' was applied to 6 files
[info] SHA-1: ed00c338faad479d3f2a17dc26844c4de9945297
[info] Packaging C:\myApp\target\scala-2.11\myApp.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 164 s, completed 2016/02/11 16:17:24
packagingが終わったら、C:\myApp\target\scala-2.11\myApp.1.0-SNAPSHOT.jar というファイルが生成され、実行できます。
PS C:\myApp\target\scala-2.11> java -jar .\myApp.1.0-SNAPSHOT.jar

WARファイル

http://terrence.logdown.com/posts/262781-play-framework-project-to-build-war-files-to-tomcat-perform
WARの場合も、build.sbtとproject/plugins.sbtを編集する必要があります。
build.sbt
……
//configuration for activator war : start import com.github.play2war.plugin._
Play2WarPlugin.play2WarSettings
//3.1 for tomcat 8,Wildfly 8, Glassfish 4, Jetty 9 //3.0 for tomcat 7,JBoss 7, JBoss EAP 6, Glassfish 3, Jetty 8 Play2WarKeys.servletVersion := "3.0"
//configuration for activator war : end
……
libraryDependencies ++= Seq(   jdbc,   cache,   ws,   specs2 % Test,   "org.mariadb.jdbc" % "mariadb-java-client" % "1.3.4",   "com.typesafe.play" %% "anorm" % "2.4.0",   "org.webjars" % "bootstrap" % "3.3.1"  //configuration for activator war )
……
project/plugins.sbt
//configuration for activator war
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.4-beta1")
https://github.com/play2war/play2-war-plugin/wiki/Configuration
プラグインのバージョン設定は上記URLをご参照ください。
activator warを実行する
PS C:\myApp> .\activator war
[info] Loading project definition from C:\myApp\project
[info] Set current project to myApp (in build file:/C:/myApp/)
[info] Wrote C:\myApp\target\scala-2.11\myapp_2.11-1.0-SNAPSHOT.pom
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript asse
ts compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] Build WAR package for servlet container: 3.0
[info] Packaging C:\myApp\target\myapp-1.0-SNAPSHOT.war ...
[info] Packaging done.
[success] Total time: 3 s, completed 2016/02/11 16:45:53
targetフォルダにwarファイルが生成されて、それをtomcatなどで配置すれば実行できるはずです。

2016年2月1日月曜日

php7 memcachedインストール失敗

  • このエントリーをはてなブックマークに追加


php7の環境にmemcachedを入れようとするとエラーが出ました。バグみたい。
●libmemcachedインストール
http://libmemcached.org/libMemcached.html  からダウンロードし解凍してインストール

./configure
make
make install  (g++が必要なので、・yum install gcc-c++)
●memcachedインストール
make の時に ,以下の様なエラーが表示される
In file included from /tmp/php-memcached/php_memcached.c:26:0: 
/tmp/php-memcached/php_memcached_private.h:44:40: fatal error: ext/standard/php_smart_str.h: No such file or directory
#include <ext/standard/php_smart_str.h>
php7でmemcachedがまだサポートされていないみたい。失敗する
参照リンク
https://bugs.php.net/bug.php?id=71139