採用ページの先輩の声を集めたサイト、「Recpe」
仕事に対する熱が冷めてしまった時などに、このサイトを見て再び熱意を持てますように。
Play FrameworkをHeroku上でデプロイしております。
PostgreSQLのコネクション数が、無料だとかなり制限厳しいですね。
cd /usr/local/src/
wget http://ja.wordpress.org/wordpress-3.9.1-ja.zip
unzip wordpress-3.9.1-ja.zip
mv wordpress /var/www/html/
mysql> CREATE DATABASE `wordpress` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL ON wordpress.* to wordpress@localhost;
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR wordpress@localhost=password('パスワード');
vim /var/www/html/wordpress/wp-config.php
vim /var/www/html/wordpress/wp-config.php
define('FS_METHOD', 'direct');あとはパーミッションの変更
cd /var/www/html/wordpress/
mkdir wp-content/upgrade
chmod 0707 wp-content/upgrade
chmod 0707 wp-content/themes
chmod 0707 wp-content/plugins
Add activator your PATH to have the command available in your cli.
cd activator-1.2.1-minimal/
./activator new
Browse the list of templates: http://typesafe.com/activator/templates
Choose from these featured templates or enter a template name:
1) minimal-java
2) minimal-scala
3) play-java
4) play-scala
(hit tab to see a list of all templates)
Enter a name for your application (just press enter for 'play-java')
OK, application "test-project" is being created using the "play-java" template.
To run "test-project" from the command-line, run:
***/activator-1.2.1-minimal/test-project/activator run
To run the test for "test-project" from the command-line, run:
***/activator-1.2.1-minimal/test-project/activator test
To run the Activator UI for "test-project" from the command-line, run:
***/activator-1.2.1-minimal/test-project/activator ui
cd test-project/今度はプロジェクトに依存するjarファイルがよしなにダウンロードされるので、しばし待ちます。
activator run
redirect(controllers.site.routes.SiteFormController.success());のように書きます。
controllers.site.routes.SiteFormController.confirm()のようにして指定します。
@Column(nullable = false, unique = true, columnDefinition = "varchar(191)")でデータベースの定義をします。他のアノテーションはバリデートルールです。
@MaxLength(value=191, message="URLは191文字以下でご入力ください。")
2.1
import com.avaje.ebean.validation.NotNull;
2.2
import javax.validation.constraints.NotNull;
avaje-ebeanorm-api is not in the list of SBT dependenciesということだそうで、EBeanの依存関係のバグでMaven Repositoryで自動取得してくれないようなので、build.sbtに以下を追記するようなので追記してみることにしました。
"org.avaje.ebeanorm" % "avaje-ebeanorm-api" % "3.1.1"
http://stackoverflow.com/questions/20520456/java-lang-nosuchmethoderror-is-chasing-me-at-cloudbeesException in thread "main" java.lang.NoSuchMethodError: com.avaje.ebean.config.AutofetchConfig.isGarbageCollectionOnShutdown()Z
Looks like conflicting version of same jar in classpathとあるように、そもそもPlay Framework 2.2系で使用しているEBeanのバージョンと
2.2ではEBeanが3.2.2になっています。
import javax.validation.constraints.NotNull;にするという結論になりました。以上。
public static Result index(int page) { List<SiteBean> resultList = SiteBeanService.getSiteBeanResultList(page); return resultList.size() == 0 ? ok("") : ok(views.html.ajax.listAjax .render(page, resultList)); }
GET /listAjax/:page controllers.ajax.ListAjaxController.index(page:Integer)
<input type="hidden" id="hasNext" value="0" /> <input type="hidden" id="page" value="1" />
$(window).on('bottom', function() { var obj = $(this); // since this ajax call might take a while if (!obj.data("loading") && $("#hasNext").val() == 0) { obj.data("loading", true); $("#loading").show(); $.ajax({ url : "/listAjax/" + $("#page").val(), dataType : "html", success : function(data) { if (data == "") { $("#hasNext").val(1); } else { $("#listContainer").append(data); } var page = parseInt( $("#page").val() ); $("#page").val(page + 1); // remove the loading text $("#loading").hide(); // now that the ajax call is done, we can re-enable this obj.data("loading", false); $("#list"+page).preloader(); }, error : function(data) { console.log(data); } }); } });
public static PagingList<Site> getSiteCriteria() { return find.where().orderBy().desc("createDate") .findPagingList(ApplicationConfigUtils.MAX_PER_PAGE); } public static List<Site> getSiteResultList(Integer page) { PagingList<Site> pagingList = getSiteCriteria(); Page<Site> currentPage = pagingList.getPage(page); return currentPage.getList(); } public static Integer getSiteResultCount(Integer page) { PagingList<Site> pagingList = getSiteCriteria(); return pagingList.getTotalPageCount(); }
public static List<SiteBean> getSiteBeanResultList(Integer page) { ArrayList<SiteBean> list = new ArrayList<SiteBean>(); List<Site> resultList = getSiteResultList(page); for (Site site : resultList) { list.add(setSiteBean(site)); } return list; }
public static final int MAX_PER_PAGE = 10;
ListresultList = SiteBeanService.getSiteBeanResultList(0);
@(message: String, description: String, beanList: List[models.beans.SiteBean])
<div class="container"> <div class="row"> @if(beanList != null && beanList.size() > 0){ @for(bean <- beanList){ <div class="col-sm-6 col-md-4"> <div class="thumbnail"> <a href="@{bean.url}"><img title="@{bean.title}" src="@{bean.thumbUrl}" alt="@{bean.url}" /></a> </div> </div> } } </div> </div>
@Entity public class Site extends Model { private static final long serialVersionUID = 3890695880010099962L; @Id public Long siteId; @Required @NotNull public String title; @Required @NotNull @Lob public String url; @CreatedTimestamp public Date createDate; @Version public Date updateDate; }個人的にはLazyLoadとかを信頼してないので、Model同士のひも付けは自前でする派です。
libraryDependencies ++= Seq( // Select Play modules javaJdbc, // Java database API javaEbean, // Java Ebean plugin //javaJpa, // Java JPA plugin javaCore, // The core Java API cache, "org.webjars" %% "webjars-play" % "2.2.0", "org.webjars" % "bootstrap" % "3.1.1", "org.webjars" % "font-awesome" % "4.0.3", "mysql" % "mysql-connector-java" % "5.1.29", "org.avaje.ebeanorm" % "avaje-ebeanorm-api" % "3.1.1")のようにして呼ぶ必要があります。
libraryDependencies ++= Seq( // Select Play modules javaJdbc, // Java database API javaEbean, // Java Ebean plugin //javaJpa, // Java JPA plugin javaCore, // The core Java API cache, "org.webjars" %% "webjars-play" % "2.2.0", "org.webjars" % "bootstrap" % "3.1.1", "org.webjars" % "font-awesome" % "4.0.3", "mysql" % "mysql-connector-java" % "5.1.29")
-> /admin admin.Routes
# Routes # This file defines all application routes (Higher priority routes first) # ~~~~ GET /index controllers.admin.ApplicationController.index() # Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.at(path="/public", file) GET /webjars/*file controllers.WebJarAssets.at(file)
libraryDependencies ++= Seq( // Select Play modules //jdbc, // The JDBC connection pool and the play.api.db API //anorm, // Scala RDBMS Library //javaJdbc, // Java database API //javaEbean, // Java Ebean plugin //javaJpa, // Java JPA plugin //filters, // A set of built-in filters javaCore, // The core Java API // WebJars pull in client-side web libraries "org.webjars" %% "webjars-play" % "2.2.0", "org.webjars" % "bootstrap" % "3.1.1" // Add your own project dependencies in the form: // "group" % "artifact" % "version" )ここのところのバージョンを変えることで、読み込むBootstrapのバージョンを変更することが可能です。
"org.webjars" % "bootstrap" % "3.1.1"対応しているバージョンやライブラリは http://www.webjars.org/ から探します。
sudo gem install sass sass -v Sass 3.2.14 (Media Mark)
resolvers += "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
addSbtPlugin("net.litola" % "play-sass" % "0.3.0")
import net.litola.SassPlugin
play.Project.playScalaSettings ++ SassPlugin.sassSettings
cd /Users/myname/Documents/workspace/PlayFrameworkRecruitConsole
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/YoshiteruIwasaki/PlayFrameworkRecruitConsole.git
git push -u origin master
git remote add origin https://github.com/YoshiteruIwasaki/PlayFrameworkRecruitConsole.git
git push -u origin master
vim ~/.activator/1.0/config.json
{"applications":[]}
/Users/myname/Documents/lib/activator-1.0.13/activator ui初回は依存関係のあるjarファイルがダウンロードされます。
Play Framework is the High Velocity Web Framework for Java and Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource comsumption (CPU, memory, threads) for highly-scalable applications. This app will teach you how to start building Play 2.1 apps with Java.
Now that you've generated your project files:
- Launch Eclipse and select Import... from the File menu.
- In the import dialog, choose Existing Projects Into Workspace and click Next.
- In the import dialog, browse to /Users/myname/Documents/workspace/PlayFrameworkAdminConsole. You should see your app's project(s) there.
- Select your project and click Finish.
If you need to (re)generate your project files, start over.
ConfigurationBuilder conf = new ConfigurationBuilder().setUseSSL(true);
Twitter twitter = new TwitterFactory(conf.build()).getInstance();
http.useSSL=trueを追加すればいけるかと思います。
[mysqld] #character-set-server = utf8 character-set-server = utf8mb4
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4;
db.default.url="jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=utf8&connectionCollation=utf8mb4_general_ci"
mysqldump -u root -p --all-database > all.sql設定ファイルも念のためバックアップをとっておきます。
cp /etc/my.cnf /etc/my.cnf.backup
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
service mysqld stop yum --enablerepo=remi update mysql mysql-server
[mysqld] #default-character-set = utf8 character-set-server = utf8 #key_buffer = 128M key_buffer_size = 128M #log-slow-queries = /var/log/mysql-slow.log slow-query-log = ON slow-query-log-file = /var/log/mysql-slow.log
service mysqld start
mysql_upgrade -u root -p