I had a tough time to set the port of a Grails project to something other than 8080. The project was set up with Gradle. I tried all the ways I can think of and found on Google but it does not work. The methods I tried include
./gradlew run -PgrailsArgs="-Dgrails.server.port.http=9090"
./gradlew run-app -PgrailsArgs="-Dgrails.server.port.http=9090"
./gradlew grails-run-app -PgrailsArgs="-Dgrails.server.port.http=9090"
./gradlew run -Dgrails.server.port.http=9090
./gradlew -Dgrails.server.port.http=9090 run
./gradlew grails-run-app -PgrailsArgs="--port=9090"
as well as out the grails.server.port.http property in build.properties, Config.groovy and build.grade. None works. It is hard.
Probably grail run-app may work with one of the above option (also using BuildConfig.groovy). But "grails run-app" always resulted a resolving error for org.aspectj:aspectjweaver:1.8.5. I don't see how to get around this way either.
Any help will be greatly appreciated.
You can also set port like this
-Dgrails.server.port=9090
when you start server using Gradle. It works for me
You are using incorrect property name I guess i.e. grails.server.port.http. It should be server.port.Hence try ... -Dserver.port=8256 etc.
Also, you could specify it in your build.gradle task which you are using to run your application as below. For example you are doing it for springboot application using gradle bootRun.(I actually don't have much working experience in grails 3.0 but have in springboot)
bootRun {
systemProperty 'server.port', '8086'
}
This will run your application on 8086 port.
In general, you could try
gradle your_task_to_run_app -Dserver.port=your_port
Also, if you have application.yml in grails 3 app(as grails 3 uses gradle and springboot.If not present you should be able to create one) then do it like below:
app:
name:Springboot+Config+Yml+Demo
version:1.0.0
settings:
counter:1
---
spring:
profiles:development
server:
port: 9001
security:
user.name: 'default'
user.password: 'default'
Let me know it works or not as haven't tried but pretty sure that it will work.
Edit: More this should help!
Hope it helps!
Related
it's great news that Grails 3.2.1 now comes with an Angular2 profile, but I don't know how to use it.
The profile description tells me that there should be the standard command like create-domain-class, but when I create an app through
grails create-app test-ng --profile angular2
I get a working angular2 project, but it even seems that this project is not recognized as grails app. When I enter the grails cli, I only get the commands like create-app which are available outside of projects.
What am I doing wrong?
your grails create-app test-ng --profile angular2
command should have created three folders in your test-ng-project-folder:
client
gradle
server
change to server and start grails command
now you should have the wellknown grails project.
but i am still on the first steps of examining the new grails-profile. so i hope i could help you.
Nowadays this layout is called "multi-project". Separate 4 the client and server applications. To make things easier, the tasks test, integrationTest, and bootRun have been created in the client application to make executing those tasks easier across the whole application.
Since Gradle executes tasks synchronously, and the bootRun task will never finish, it is important to execute it in parallel. At the root of the project:
./gradlew bootRun --parallel
Opening things also separately by 2 instances of your IDE or preferred text processor.
see the docs
grails list-profiles
show list of available profiles, I suggest you use this because for example now angular2 profile is angular and angular1 is angularJS.
Please note: Although I'm using the Grails Shiro plugin I believe this to be a core Grails problem, having nothing to do with the plugin whatsoever.
Mac (Yosemtie) and Grails 2.4.5 here. Here's the top 2 lines from my Config.groovy:
String configFileAbsPath = System.getProperty('configFileAbsPath')
grails.config.locations = [ "file:${configFileAbsPath}" ]
So to run locally I do something like:
grails -DconfigFileAbsPath=/Users/myuser/tmp/myapp.properties run-app
When I run this exact invocation, my app starts up and behaves just fine.
However, in non-local environments I want my config file to live under /opt/myapp/myapp.properties. So on my local machine I create a /opt/myapp directory, and then ran chmod -R 777 /opt/myapp. I then copy myapp.properties to it and run:
grails -DconfigFileAbsPath=/opt/myapp/myapp.properties run-app
This produces the following stack trace:
| Error Error generating web.xml file (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
groovy.lang.MissingPropertyException: No such property: shiro for class: java.lang.String
at ShiroGrailsPlugin$_closure4_closure30_closure34.doCall(ShiroGrailsPlugin.groovy:248)
at ShiroGrailsPlugin$_closure4_closure30_closure34.doCall(ShiroGrailsPlugin.groovy)
at ShiroGrailsPlugin$_closure4_closure30.doCall(ShiroGrailsPlugin.groovy:243)
at ShiroGrailsPlugin$_closure4_closure30.doCall(ShiroGrailsPlugin.groovy)
at ShiroGrailsPlugin$_closure4.doCall(ShiroGrailsPlugin.groovy:242)
I seriously doubt that the location of an external config file, or the file permissions set on the config file (or its parent dir) would break the Grails Shiro plugin. I think this is just a misleading Grails/Groovy exception. Most likely some kind of security exception is causing something to not load/populate correctly (and fail silently), and then when Grails Shiro kicks in during run-app, its missing something that should be there and is causing run-app to die.
Any ideas as to what is going on, or what the fix is?
Update: Running grails clean, grails clean-all and/or grails refresh-dependencies prior to invoking grails run-app do not help/solve this error either.
I generally prefer to have .groovy file for external config rather than .properties because I can write printlns into it to check whether the file is loaded or not.
I have a grails 3.0 application packaged as war file, and I would like to run it with java command line. Things looks simple from the reference guide: java -jar my_war_file_name. But I cannot find a way to pass in the profile (dev/test/prod), and also it looks like -D option cannot overwrite the configuration as well. Any idea?
Best Regards
Sorry, I found the problem. I should put -D in front of -jar. So this is working:
java -Dgrails.env=prod -Dserver.port=xxxx -jar my_war_file
I'm trying to get my feet wet with grails, so I'm following a tutorial to get going with a sample project. I downloaded grails 2.3.2, added the environment variables for the command prompt commands, and successfully created a project by using >grails create-app teamwork. Calling >grails run-app after changing to the project directory successfully downloads all requisites, but then I get . I know that this exception doesn't reveal much, but do you guys have any ideas on why? I am running command prompt in admin mode, if that means anything.
Try not forking the JVM in BuildConfig.groovy, if I recall correctly. If that works, then check the JIRA issues for Grails 2.3.2.
I want to change the httpPort from the default of 8080 for the Jetty Grails plugin. I cannot set the Jetty httpPort property via a system property and/or Gradle property.
System property: gradle jettyRun -DjettyHttpPort=9090
Gradle property (gradle.properties): jettyHttpPort=9090
Right now you have to make a change to your Gradle build script (like adding a configuration task) to make this work. There are JettyPluginConventions with a function to setHttpPort(int) but I do not know how to implement it.
http://www.gradle.org/releases/1.0-milestone-3/docs/javadoc/org/gradle/api/plugins/jetty/JettyPluginConvention.html#setHttpPort(java.lang.Integer)
http://www.gradle.org/jetty_plugin.html
I had the same problem, and documentation for Gradle is very general and vague. I sometimes think that only Gradle developers are able to get full potential of this great tool :)
Right now the way is to add following to gradle build script:
jettyRun {
httpPort = 9000
}
It looks you cannot set this value in command line. There was an issue for that, GRADLE-1224, but it was closed as "Won't Fix" because
The Jetty plugin has been deprecated and is scheduled to be removed with Gradle 4.0. We are not going to work on this issue anymore.
You can set properties like httpPort via JettyPluginConvention
convention.plugins.jetty.httpPort = 9090
You can start with below command
gradle jettyRun -DhttpPort=9000
However, the task jettyRunWar doesn't seem to pick port 9000 and still uses default port. May be a bug in gradle jetty plug-in.
Have you tried -Djetty.port=9090 as a JVM parameter?