doWithDynamicMethods not being Called - grails

When I create a production war (grails war --nojars) my doWithDynamicMethods is not being called in a production environment. The code works in the dev env (ie grails run-app)
Here is some of my code:
PDFFormsGrailsPlugin.groovy (in PDFForms (plugin) directory) :-
def doWithDynamicMethods = { ctx ->
println "Adding renderPDFForm to controller";
for (controllerClass in application.controllerClasses) {
updateControllers controllerClass.metaClass
}
}
BuildConfig.groovy (in Application using Plugin) :-
grails.plugin.location.'pdff-orms' = "../PDFForms"
We are using Grails 1.3.5 on Windows XP, The Build is called from STS 2.3.3.CI-R5462-B20
Thanks in advance.

Check if the plugin is referenced in your grails.xml.
Read this Nabble thread
And this jira
P.S. Why not you upgrade to grails 1.3.7 at least?!

Related

Grails 3 JNDI datasource for Tomcat, Weblogic, Glassfish - Vs Grails 2

I'm experimenting with migrating from Grails 2 to Grails 3.
In Grails 2, I used this as my JNDI name within datasource.groovy file, within the Production-env
jndiName = "${(System.getProperty('catalina.home') && (System.getProperty('java.class.path')).trim().toLowerCase().indexOf('tomcat') > 0 ) ? 'java:comp/env/' : ''}jdbc/myGrails"
I found that worked well for me for Glassfish, Weblogic, and Tomcat.
However, when i try this in Grails 3, within the application.yml:
jndiName: ${(System.getProperty('catalina.home') && (System.getProperty('java.class.path')).trim().toLowerCase().indexOf('tomcat') > 0 ) ? 'java:comp/env/' : ''}jdbc/myGrails
I get this error when running "grails run-app":
| Error Error occurred running Grails CLI: mapping values are not allowed here
in 'reader', line 123, column 169:
... mcat') > 0 ) ? 'java:comp/env/' : ''}jdbc/traxGrails
^
(Use --stacktrace to see the full trace)
If I do use this in Grails 3:
jndiName: java:/comp/env/jdbc/myGrails
Then it works fine when using Grails run-app, and also works fine to deploy the WAR to Tomcat.
Can someone help me in getting my "jndi expression" from Grails 2 to work in Grails 3?
It looks like you're trying to use groovy syntax in a yml file, which does not work. You can create an application.groovy file (which will be merged with the application.yml file) if you want to use groovy syntax.
Also take a look at the many ways spring-boot allows you to inject properties via env variables, properties, yml, etc. http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

What classspath is used for executing Grails' application.groovy

What classspath is used for compiling/executing Grails' application.groovy?
In my application.groovy, I instantiate a custom class (contained in a dependency's jar) and assign it to one of the config properties, like so:
environments {
production {
configProperty = new com.example.CustomClass()
I recently upgraded my application from Grails 3.1.5 to 3.2.2, and now this no longer works.
I receive an error like the following when I try to run grails run-app:
Error occurred running Grails CLI: startup failed:
script14788250424471597489853.groovy: 43: unable to resolve class com.example.CustomClass
# line 43, column 33.
configProperty = new com.example.CustomClass()
(Notice that the code is in the production block, but I'm running in development (run-app). That makes me think it's the compilation of this script that is failing.)
So I'm guessing I just need to add my dependency (that contains the CustomClass) to the appropriate classpath, but I'm not sure which one.
I'm using gradle, and have the following in my build.gradle file, to pull in the dependency containing CustomClass:
buildscript {
dependencies {
classpath "com.example:custom-module:1.1"
// ...
dependencies {
compile group: 'com.example', name: 'custom-module', version:'1.1'
}
The grails-app/conf/application.groovy file shouldn't reference application classes because it is read before compilation. If you wish to reference application classes in configuration please use grails-app/conf/runtime.groovy

Grails defaultPackage ignored?

When I use create-controller on the command line or in IntelliJ, defaultPackage is ignored. Instead, the controller (or service, etc.) is placed in '#artifact.package.path#':
| Enter a command name to run. Use TAB for completion:
grails> create-controller ThingController
| Created grails-app/controllers/#artifact.package.path#/ThingController.groovy
| Created src/test/groovy/#artifact.package.path#/ThingControllerSpec.groovy
I'm not sure if this is a bug in my code or Grails, perhaps because I moved config from application.yml to application.groovy:
grails{
profile = 'web'
codegen{
defaultPackage = 'com.madeupname.web'
}
spring {
transactionManagement {
proxies = false
}
}
}
Maybe there's a typo I'm blind to? I'm using Grails 3.1.7 on JDK 8.
This will work if you define the property in grails-app/conf/application.yml.
---
grails:
codegen:
defaultPackage: com.madeupname.web

Quartz Plugin for Grails - OutOfMemoryError in the Production environment

I am trying to deploy my Grails 2.1.1 application to cloudfoundry.com. On my local computer the application runs without problems. When removing the Quartz plugin dependency from the BuildConfig.groovy I'am able to start the application on cloudfoundry successfully.
Dependency:
compile ":quartz:1.0-RC5"
The grails cf-logs prints the following error:
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space
Below see my Job:
package de.tum.wi.fm.game
import org.quartz.JobExecutionContext
class StartGameJob {
def execute(JobExecutionContext context) {
def gameRoundId = context.mergedJobDataMap.get('gameRoundId')
if(gameRoundId) {
GameRound gameRound = GameRound.get(gameRoundId)
if(gameRound) {
Game game = gameRound?.game
game.currentGameRound = gameRound
game.save(flush: true)
}
}
}
}
The trigger is placed in a service:
def jobParams = [gameRoundId:gameRound.id]
Date gameRoundEndDate = gameRound.endDate.toDate()
ChangeRoundJob.schedule(gameRoundEndDate, jobParams)
The OutOfMemoryError exception determines that the JVM hasn't enough memory assigned. You need to increase the memory of cloudfoundry instance and consequently increase memory of the JVM.
Try to execute following commands when deploying your application:
grails -Dgrails.env=production cf-push --memory=2048 --no-start
grails -Dgrails.env=production cf-env-add JAVA_OPTS -Xmx1024m -XX:MaxPermSize=512m
grails -Dgrails.env=production cf-start
The first command will push (deploy) the application into the cloudfoundry instance and doesn't start it.
The second will set JVM environment variables, sufficient memory settings.
Third command starts the application.
Have you tried assigning more memory to the application? You can do this using VMC;
vmc scale [application name]
Follow the prompts and VMC should ask how much memory you wish to assign.

Grails and release plugin

I'm trying to use the release 2.0.4 plugin to deploy my war through grails 2.1.1 to artifactory server.
My BuildConfig.groovy has:
grails.project.repos.snap.url = "http://server:8080/artifactory/apps-snapshot-local"
grails.project.repos.snap.username = "user"
grails.project.repos.snap.password = "password"
grails.project.repos.rel.url = "http://server:8080/artifactory/apps-release-local"
grails.project.repos.rel.username = "user"
grails.project.repos.rel.password = "password"
grails.project.repos.default = "rel"
When I just do the "grails maven-deploy" it works and deploys to my rel server as expected. When I try to override the default target through the command line I get failures.
grails maven-deploy --repository=snap
I get this:
| Done creating WAR snap
| POM generated: C:\dev-git\DBUpdateWeb\target/pom.xml.
| Error Error deploying artifact: C:\dev-git\DBUpdateWeb\target\DBUpdateWeb.war (The system cannot find the file specified)
| Error Have you specified a configured repository to deploy to (--repository argument) or specified distributionManagement in your POM?
When I do specify the --repository tag it doesn't generate a war even though it says it did. Any help is appreciated. Thanks in advance.
Try grails maven-deploy "--repository=snap".
Also, specify app.version in application.properties so that the WAR will be standard compliant (1.0-SNAPSHOT for publishing to the snapshots repository and 1.0 for releases), and comment out the grails.project.war.file line in BuildConfig.groovy.

Resources