Has anyone had success with Grails 4 / Java 11 and using DCEVM for hotswapping during development? - grails

We upgraded to Grails 4 / Java 11 and lost hot-swapping capabilities during development. I tried DCEVM but the application wouldn't start (errors on first withNewSession call).
Has anyone had success with getting Grails and DCEVM to work together?

I've got hotswap working with Grails 5.1.2 but the Hibernate plugin causes a
org.hibernate.HibernateException: No Session found for current thread
so I had to disable the plugin. This means any changes to domain classes will still need a restart.
You'll need a copy of groovyReset.jar to avoid random errors due to Groovy caching methods that have been replaced by hotswap.
sdk install java 11.0.9-trava
sdk use java 11.0.9-trava
Add a copy of groovyReset.jar to your project root
Add the following to the bootRun jvmArgs in build.gradle:
'-XX:HotswapAgent=fatjar',
'-javaagent:groovyReset.jar'
Create src/main/resources/hotswap-agent.properties containing:
disabledPlugins=Hibernate
autoHotswap=true
You should now be able to start Grails and any code changes will be picked up without restarting.

Recently I tried with Hybris2005 + Java 11 + Windows + Eclipse.
Follow below given steps and do modification as per your need.
DCEVM 11 Configuration Step.
Download and extract java11-openjdk-dcevm-windows.zip in your local machine
Set JAVA_HOME=D:\java11-openjdk\dcevm-11.0.10+3 (Adjust the path as per location in your system)
In eclipse go to windows->Preference->Installed JRE and set JRE home to D:\java11-openjdk\dcevm-11.0.10+3
4 In local.properties adjust the property tomcat.debugjavaoptions as below
tomcat.debugjavaoptions=-XX:HotswapAgent=core -javaagent:D:/java11-openjdk/dcevm-11.0.10+3/lib/hotswap/hotswap-agent.jar=disablePlugin=Log4j2,disablePlugin=Spring,disablePlugin=Proxy,disablePlugin=AnonymousClassPatch,disablePlugin=ZK,autoHotswap=true -Djava.locale.providers=COMPAT,CLDR -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n -Xmx4G -Xms2G
Also, please set ANT_HOME environemnt variable so that we don't to run setantenv.bat from \hybris\bin\platform and update the PATH variable accordingly.
Perform ant clean all and start hybris in debug mode.
Add System.out.println() statement in your code and then execute ant build command from that specific extension folder.
Verify if HOT swap is done.

Related

Error running Grails 3 application on CMD

I am new to Grails and never made any project on it. I followed some tutorials and downloaded both Grails and JDK and set my environment variables exactly as specified, but when I tried to run the application, I got this error and my application is not running:
Error initializing classpath: could not determine java version from '10.0.2'
I just used CMD and none of the IDE is used, please help me solve this problem.
First check classpath of both for Java & Grails by running these command java -version & grails -version
If you found problem in classpath then solve by this way http://grails.asia/grails-tutorial-for-beginners-setup-your-windows-development-environment/
Although its better to use Java 8, not Java 10

Grails/aNimble on Windows : Getting cannot find the specified path

I am trying to setup aNimble on Windows following this article.
I have setup the Java and MySQL (xampp) on Windows and both are working properly.
Now, as the final step I need to execute
grails prod execute-database-scripts-all
but I am getting cannot find the specified path. Even when I type grails only I get the same error. I have zero experience in Grails, but it seems that I need to install Grails first on the PC. Until I do this, I want to know is there anything else that I need to do this to successfully execute this command.
What are the three portions of this command grails, prod and execute-database-scripts-all
This error means that Windows is unable to find grails executable anywhere it looks (in any paths specified in PATH system property) when you typing grails command. You may have to follow this guide in order to install grails application framework properly in your system (also, make sure you are installing a correct version of grails compatible with your distribution of aNimble) and then retry.
Grails is a web application framework and which provides a set of tools to develop, build and run web applications like aNimble, prod is a command line option for grails telling it to run in a production mode and execute-database-scripts-all is aNimble-specific command to initialize it's database.

Cannot run Grails from command prompt

I’ve added a GRAILS_HOME environment variable, which points to the folder in which I extracted the Grails distribution zip, and I’ve added %GRAILS_HOME%\bin to my path. Yet after I open a new command prompt, the “grails” command is still not found. Does anyone have any clue as to why this is happening?
I’m running Grails 2.2 on Windows 7.
I have the same problem on Windows 7 64 bit and Grails version 2.*
By removing local neither maven repository nor installed plugins repository doesn't help.
I found - just set properties of %GRAILS_HOME%/bin/grails.bat and startGrails.bat as Run in compatibility mode: Windows XP (Service Pack 3).
To do that You need to have local PC Administrators rights.
/igors
have you create JAVA_HOME in there?
Maybe you are experiencing [STS-2530] Problem deploying Grails App if workspace path has a space. Jira shows the issue as resolved but it would not hurt to check that you do not have a space in your workspace path as it my trip up grails.
Do the following.
Go to your command prompt, execute the Path command. If everything has been set right your paths should show up as complete paths starting with C:... If the paths show up with the % sign that means your paths need to be set correctly. I did noticed that in your example you have used the forward slash - I am assuming that is a typo, because that will be a problem.
Another way to trouble shoot the issue is CD to the location C:\Grails\bin, execute the command grails.bat, if it executes you are in a good place that means you have to tweak your paths - following this path might give you a clue about other issues....
You might want to check the bin folder of your grails installation. The grails.bat file could be missing. I had this problem today and solved it by downloading the zip file again.

How do you manage developing with multiple versions of Grails using Windows?

We've been using Grails for a little while now and have been through a few Grails versions now. We don't always want to migrate our 'older' apps immediately but often use a newer version for new development. Changing the Windows environment variables is inconvenient since I sometimes have to work on two related projects at the same time that are running different versions of Grails.
In Linux, I'd probably create wrapper scripts or aliases to allow me to specify on the command line a version switch but I don't believe Grails supports this.
How are others that need to code against multiple versions of Grails managing it?
Update:
I created a gv.bat file to set the GRAILS\_HOME and PATH environment variables. I added a GRAILS\_INSTALLS environment variable (c:\usr\local\grails on my box) and removed the %GRAILS_HOME%\bin reference from my PATH.
gv.bat
#echo off
SET GRAILS_HOME=%GRAILS_INSTALLS%\grails-%1
SET PATH=%GRAILS_HOME%\bin;%PATH%
To do any Grails work I run > gv 1.1.2 or whatever version I need to work with. I'd like to figure out how to do a string replace in the PATH to change the value but that turned out to be difficult for me
I have a couple of bat files which changes the GRAILS_HOME and the system PATH according to which version I'm using.
It's not the most beautifull solution at all, but at least works for me.
I have a batch file, that looks like below.
#ECHO OFF
if "%1"=="231" goto grails231
if "%1"=="232" goto grails232
if "%1"=="233" goto grails233
if "%1"=="234" goto grails234
goto end
:grails231
set GRAILS_HOME=F:\softwares\grails-2.3.1
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails232
set GRAILS_HOME=F:\softwares\grails-2.3.2
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails233
set GRAILS_HOME=F:\softwares\grails-2.3.3
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails234
set GRAILS_HOME=F:\softwares\grails-2.3.4
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:end
It can be run like 'setgrails 233' and it will set the grails 2.3.3
IntelliJ allows you to specify which version of Grails to apply as a per-project facet configuration. The Eclipse plugin has yet to achieve this level of abstraction.
It's now MUCH much later, and GVM is not the tool it once was. Instead, I use SDKMAN (https://sdkman.io/) and, with Windows getting some linux-like tooling, or using Cygwin, etc. it's installable on Windows.
------ OLD answer below ------
GVM is a tool for unix/mac environments to manage Groovy/Gradle/Grails/more versions, and someone finally made a Windows equivalent called Posh-gvm (short for Power-shell GVM). It's very useful and easy to use to download and configure your environment for whichever version of these tools you want to use at any point in time.
If you're using an IDE, posh-gvm is still a great way to download/install the new versions as they come out, and your IDE can point into the posh-gvm install directories.
I have the same issue as you. For my concern, I have written a batch script (grails_version.bat) accessible from my Windows PATH home.
Set up your GRAILS_HOME to your standard Grails version and each time you want to run a Grails app into another version than the standard one, open a command prompt, run the batch script (>grails_version) and run your grails commands (ex: grails run-app).
If your are using IntelliJ, you can configure the grails version per application.
Here is the code:
#echo off
set v11=1.1
set v111=1.1.1
set v12M2=1.2-M2
set v12M3=1.2-M3
set v12M4=1.2-M4
set /p grails_version= What is the grails version (%v11%, %v111%, %v12M2%, %v12M3% (default), %v12M4%)?
if "%grails_version%" == "%v11%" goto :set_grails_home
if "%grails_version%" == "%v111%" goto :set_grails_home
if "%grails_version%" == "%v12M2%" goto :set_grails_home
if "%grails_version%" == "%v12M3%" goto :set_grails_home
if "%grails_version%" == "%v12M4%" goto :set_grails_home
if "%grails_version%" == "" goto :set_grails_home_default
:no_valid_input
echo The input version is not valid
exit
:set_grails_home_default
set grails_version=%v12M3%
:set_grails_home
set GRAILS_HOME=D:\Install\grails\grails-%grails_version%
path = %GRAILS_HOME%\bin;%PATH%
echo GRAILS_HOME=%GRAILS_HOME%
Enjoy.
I do that in Windows as below.
So I just change GRAILS_VER environment variable.
I can change my grails version anytime.
On Linux/Mac, GVM is a fantastic tool for installing and working with multiple versions of Grails, Groovy, etc. You can't use GVM itself on Windows1, but there is a clone posh-gvm that will run under Powershell on Windows.
AFAIK this is because Windows doesn't support symlinks
The thing I would change about these answers is the PATH handling. Each time you run the script and change versions, you will extend your path one more node. It works, but messy. Try creating a $path2 with no reference to your JAVA_HOME or GRAILS_HOME and the path become path2+grails+java. Example: set PATH="%PATH2%;F:\softwares\grails-2.3.1;path2java7.
The only reason I add the Java7 reference is that I need Java 6 for my older grails app and Java 7 for newer grails.
Check out this link, it explains exactly how to do that using cygwin and mapping several aliases.
Also, learn how the plugins directory work and replicate it several times for each version of Grails. I also use global plugins for the ones I use often, like tomcat, hibernate, dbUtil, console, etc.
Say you want to switch between 1.1 and 1.2M4 - you could have those directories setup with the plugins you are using:
c:\Users\username\.grails\1.2-M4\projects\projectname\plugins
c:\Users\username\.grails\1.1.1\projects\projectname\plugins
Then, take applications.groovy and make several copies, like
application.groovy.1.1
application.groovy.1.2M4
Now, to switch, you just need to rename the application.groovy.X to application.groovy and you are good to go (after running grails clean of course):
grails1.1 run-app
grails12M4 run-app
Lastly, there are other differences between versions (i.e. new 1.2 is introducing dependencies DSL), but most of the time things are backwards compatible enough that you can come up with a common denominator.
Some answers are outdated.
Seems that the best option nowadays is SDKMAN!:
SDKMAN! installs smoothly on Mac OSX, Linux, WLS, Cygwin, Solaris and FreeBSD. We also support Bash and ZSH shells.
Is also possible to install on Windows, but SDKMAN "can not be installed natively on Windows and requires WLS, Cygwin or MSYS+MinGW".
After that, you can choose the Grails SDK and which version you want. For example:
sdk install grails 1.3.7

Error in Grails

Anyone knows how to fix this ?
It works fine on my env (Me being the developer) and doesn't work on my colleagues machine who unzips the whole
Welcome to Grails null - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: C:\abc\products\grails-1.1
Base Directory: C:\abc\products\foo\bar
Running script C:\abc\products\grails-1.1\scripts\RunApp.groovy
Environment set to development
Application expects grails version [1.1], but GRAILS_HOME is version [null] - us
e the correct Grails version or run 'grails upgrade' if this Grails version is n
ewer than the version your application expects.
Some clarifications
1) There has been no Grails version change , either on my machine or my colleagues machine. In fact some of them are installing for the first time
2) Under C:\Documents and Settings\myfriend.grails I can see a folder called 'null'
I tried removing this folder - but it gets created he runs my application
3) The way I am giving him the release is- I unzip the whole folder and he unzips it
SO there are three steps
A_ grails create-app to create the APp
B_ Unzip my folder to replace the generated folder
C_ Grails run-app
Things are fine after the step A- but degenerate after Step C
It appears that his Grails installation is corrupted or not set up correctly. I would have him reinstall a fresh copy of Grails - http://www.grails.org/Installation and try again.
The error that you are getting is telling us that the application that you are trying to run is identified as version 1.1 and I assume that this is correct. The fact that Grails is not able to identify what version is installed makes me point to a corrupted or mis-configured Grails installation
If he types 'grails' at the command line what does he see?
I found the problem.
This was because I had added a file- build.properties
And since the file was there- it was expecting it to have certain properties defined in it
Once I renamed it to something else- it started to work

Resources