2017-03-29 16 views
1

私はgrails 3.2.8を使用しています。私はそれにウェブ機能を持っている私のgrailsプロジェクトから実行可能なwarファイルを生成しています。しかし、私は、同じgrailsプロジェクトからビルドする実行可能なjar/warから、(cronジョブとして)本番環境で実行できるようにしたいカスタムgrailsコマンドも書きました。私は自分の開発環境で "grails run-cmd ..."として実行できますが、実行可能なjar/warファイルをデプロイして、実行可能なjar/warからカスタムコマンドを実行できるようにしたいと考えています。言い換えれば、Web用のwarファイルを1台のサーバーに配備したいのですが、いくつかのcronジョブの実行可能なjarファイルをすべて1つのgrailsプロジェクトから配備したいと考えています。私はwarファイルのビルド/実行方法を知っています。しかし、プロジェクトから実行可能なjarファイルを生成して、自分のカスタムgrailsコマンドをcronジョブとして実行できるようにする方法は本当に分かりません。誰も私にこれを行う方法を教えてもらえますか?grails実行可能jar/warからカスタムgrailsコマンドを実行する方法

+0

希望すると助かります。http://stackoverflow.com/questions/32153380/how-to-run-grails-commands-after-deploying-war-to-tomcat-in-production –

+0

クイックレスポンスのおかげで、あなたが投稿したリンクで議論された解決策は、私が探しているものではありません。私が今持っている最良の解決策(あなたのリンクにも言及されています)は、grailsプロジェクトをソース形式でプロダクションに展開し、cronジョブから "grails run-command"を実行することです。それは単一の実行可能なjarファイルとして実行し、そのように私のcronジョブを実行します。これは可能なはずですが、私はそれを行う方法がわかりません(そして、grailsのドキュメントはここでは助けになりません)。 –

答えて

2

私はうまくいくと思われるものを見つけました。私は私のGrailsプロジェクトのApplication.groovyクラスはこのように見えるように変更されました:私も「コンパイル」から「コンソール」からのGrails-コンソールの依存関係のためにbuild.gradleに依存関係を変更した

import grails.boot.GrailsApp 
import grails.boot.config.GrailsAutoConfiguration 
import grails.ui.command.GrailsApplicationContextCommandRunner 

class Application extends GrailsAutoConfiguration { 
    static void main(String[] args) { 
    if (args.length > 0 && args[0] == "run-command") { 
     // If the first argument is 'run-command', then we just want to run a command as if we were running 
     // 'grails run-command <grails-custom-command> <args>...'. We are adding the capability of running commands here 
     // because this is the class that is run from the executable war generated by running 'grails war'. If we just do the same 
     // thing that grails does to run a command, then the commands seem to execute just fine. 
     args = args.tail() 
     // The following code is copied from GrailsApplicationContextCommandRunner.main(). It is what grails does to make 
     // 'grails run-command' work from the grails console/command line. When upgrading grails, it may be necessary to update 
     // this code... 
     def runner = new GrailsApplicationContextCommandRunner(args[0], Application) 
     runner.run(args) 
    } else { 
     GrailsApp.run(Application, args) 
    } 
    } 
} 

compile "org.grails:grails-console" // changed from 'console' dependency since we want to be able to run custom grails commands from the executable jar/war 

これは、GrailsApplicationContextCommandRunnerクラスがgrails-consoleにあるためです。代わりにこれらの変更により

、私はまだでwarファイルを実行することができます。

java -jar myWarFile.war 

しかし、私はまた、今、このようなまったく同じwarファイルと私のカスタムコマンドを実行することができています

java -jar myWarFile.war run-command my-command <command args> 

これを行うにはもっと良い方法があるはずですので、grailsチームがコメントしてもいいでしょう(そして、より良い方法がない場合、grailsチームは、 Grailsの機能要求として実行可能なwarファイル)が、私はこのようにして、実行可能なwarファイルからカスタムコマンドを実行することができます。

関連する問題