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
Related
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.
I'm trying configure PyScripter 2.5.3 to use a version of Python that is installed in a non-standard install location (i.e., c:\MyProj\Python27).
NOTE: I also have ActivePython 26 and 27 also installed, in the default locations c:\python26 and c:\python27)
I have a short program that simply dumps the python path to verify that I have the correct version:
import sys; print( "\n".join(sys.path) )
When I'm using the "desired version", I'll see "c:\MyProj\Python27\lib" show up on the path.
I've looked at several postings (one is How to change the version of python that pyscripter uses) and most just say the defaults work and the defaults do work. I'm trying to use a non-default directory.
I've used Tools | Configure Tools to set the Python Interpreter, and Command Prompt to run "MyProj" version of python.
So Tools | Python Interpreter, starts c:\MyProj\Python27\python.exe
Also Tools | Command Prompt, starts c:\MyProj\Python27\python.exe version.
But I can't get the Python IDE to use the desired version when I use "Run | Debug (F9)".
I've configured Tools | Options | IDE Options | Python engine type = peRemote.
I've also tried internal.
I've tried starting PyScripter from the command line with the following options (none of these examples worked)
...\PyScripter.exe --python27 --pythondllpath=C:\MyProj\Python27
...\PyScripter.exe --python27 --pythondllpath=C:\MyProj\Python27\python27.dll
...\PyScripter.exe --python27 --pythondllpath C:\MyProj\Python27
...\PyScripter.exe --python27 --pythondllpath C:\MyProj\Python27\python27.dll
I've tried having only my version of python on the windows PATH (removing c:\Python27)
set PATH=C:\MyProj\Python27;%PATH%
...\PyScripter.exe
This has also failed to work.
Has anyone had success at using a non-standard location? If so what steps were followed?
I don't know if this is the best way to do it, but those are the two ways I did it:
WAY 1 (The best of two)
Go to PyScripter>>Tools>>Options...>>Custom Parameters... and add the following values
1. PythonDir = C:\Program Files\CustomPythonInstallation
2. PythonExe = C:\Program Files\CustomPythonInstallation\python.exe
3. PythonVer = 3.3.3
Note: Adapt the Name = Value pairs above to your case.
And close the window with OK button.
Now select PyScripter>>Run>>Python Engine>>Remote and your are ready to go.
WAY 2 (The more temporary solution)
Go to PyScripter>>Run>>Configure External Run...
set the "Application:" field to your python.exe file
Close the window with OK button.
Make sure you run your scripts with PyScripter>>Run>>External Run (Alt+F9)
I hope this helped, good luck.
I'm using two different pythons, tried to use pyscripter with both, but it kept messing up. My simple solution was to download the standalone pyscripter that doesn't use the registry, put copies into two different directories, then set each up for the different py. You can then right click on their icons and set them to start in the proper directories. You can also make two cmd icons and set them respectively so you have a command line. The command line icon can also be set to start in your working directory, although that's normally one level below python, and if it isn't on the path, you have to type ../python to get it (or use a keyboard macro for that.) This works trouble free.
I did delete both pythons and removed them from the system path just in case pyscripter looked for them. Then I installed 2.7 and set up the first scripter. I installed 34 and set up the second. Oddly, the scripters found the correct py each time - I imagine they go for the highest one. But you can also set that in scripter options. And frankly, it may not be necessary to delete py**. If not deleting them doesn't work you can just make a fresh copy of scripter and try again, since that will be a new standalone. For all I know you can reinstall python on the path once pyscripter is set up for each. I haven't tried that. Fiddle around. You can always make a new copy of the pyscripter standalone directory if things don't work out ;')
The interactions between the registry, the path, and the installed pyscripter just led to too many headaches.
Oh, pyscripter doesn't seem to play well with 3.4 but there's a fixed exe for your 3.4 standalone, here - just replace the 3.4 standalone python.exe with this one:
https://pyscripter.googlecode.com/issues/attachment?aid=7680027000&name=PyScripter-Updated.7z&token=ABZ6GAd40xS88r5vwgY9m8Y18vSFKN8q3g%3A1421517339924
I am a newb with python and just learning what to do.
I am using pyscripter and have been for a while whilst learning.
I am now going through an online course which is taught in 2.6, yet my pyscripter uses the latest.
I need to know how to change it to use an older version, I have seen replies about changing the PATH variable but not where it is or how to do it.
I have 3 versions of python on my machine, 25,26 and 33.
I don't know if this is the best way to do it, but those are the two ways I did it:
WAY 1 (The best of two)
Go to PyScripter>>Tools>>Options...>>Custom Parameters... and add the following values
1. PythonDir = C:\Program Files\CustomPythonInstallation
2. PythonExe = C:\Program Files\CustomPythonInstallation\python.exe
3. PythonVer = 3.3.3
Note: Adapt the Name = Value pairs above to your case.
And close the window with OK button.
Now select PyScripter>>Run>>Python Engine>>Remote and your are ready to go.
WAY 2 (The more temporary solution)
Go to PyScripter>>Run>>Configure External Run...
set the "Application:" field to your python.exe file
Close the window with OK button.
Make sure you run your scripts with PyScripter>>Run>>External Run (Alt+F9)
I hope this helped, good luck.
The easiest way I know (on Windows) is, having used the installer executable, I select from the Start menu's PyScripter folder whichever version of Python I want to run.
You can modify the PYTHONPATH (under Pyscripter>>Tools, for instance)
You can modify your External Python Interpreter with Pyscripter>>Modify Tools>>Python &Interpreter>>Modify
You can modify the default Python engine used with Pyscripter>>Options>>IDE Options>>Python Interpreter>>Python Engine Type
You can simply redirect Pyscripter to see the environment of a different Python distribution.
In Windows, do this by assigning PYTHONDLLPATH in the Pyscripter shortcut. You can r-click on the shortcut, access its properties and then set the target to:
[Pyscripter executable dir] --PYTHONDLLPATH [Python distribution dir]
See this image to help you out:
setting a shortcut target
For example, in my Win10 64-bit computer I have a Python 2.7.8 installation back from when I installed ArcGIS, which is automatically recognized by my 32-bit Pyscripter installation.
In the same computer, I also have Anaconda installed with two environments that feature two 64-bit Python distributions:
2.7.14 in "C:\ProgramData\Anaconda2"
3.6 in "C:\Users\bouzi\AppData\Local\conda\conda\envs\py3"
When I installed a 64-bit version of Pyscripter, that Pyscripter version couldn't even open, as it couldn't find the conda distributions. I had to point them to it by replacing the shortcut target to:
"C:\Program Files\PyScripterx64\PyScripter.exe" --PYTHONDLLPATH "C:\ProgramData\Anaconda2"
You can create three Pyscripter shortcuts that point to these different installations of Python within your system. It's probably not the optimal way to deal with this but it works, and allows you to combine Anaconda environments with Pyscripter.
You can also read more on opening non-standard python distributions with PyScripter from this link.
Run->Python Versions -> setup Python Versions -> Add... select folder
p.s.
python 3.7.3 - ok,
still python 3.10.5 could not be identified by PyScripter in such a way (actually works with WAY_1 Solution in this thread but pip install under such env. not succeed afterwards)
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.
As I can run multiple versions of groovy / grails without having to change settings?
GVM (Groovy enVironment Manager) is a great option if you're on Mac, Linux, Solaris, or Windows with Cygwin. GVM supports the installation and management of Groovy, Grails, Griffon, and Gradle.
If Grails is your primary concern and you use a Windows PC in a locked down enterprise where Cygwin isn't an option, look at Gravy or write a batch file as noted above.
It's only about GROOVY_HOME/GRAILS_HOME and PATH environment variables. Start your Grails application from a bat file/shell script which sets these two variables, and you're fine.
Grails distinguishes settings stored in home/.grails for different versions, so versions won't clash there.
If you're on linux or osx, theres a shell script here which might help, and an alternative script is here
I am using 7 grails version on my ubuntu machine . put the code below at the bottom of .bashrc file.
function switchGrails() {
echo “Switching to grails version: $1″
sudo rm /opt/grails
sudo ln -s /opt/$1 /opt/grails
echo “Done!”
}
alias grails225=’switchGrails “grails-2.2.5″‘
alias grails224=’switchGrails “grails-2.2.4″‘
alias grails223=’switchGrails “grails-2.2.3″‘
alias grails233=’switchGrails “grails-2.3.3″‘
alias grails235=’switchGrails “grails-2.3.5″‘
alias grails237=’switchGrails “grails-2.3.7″‘
alias grails2311=’switchGrails “grails-2.3.11″‘
After save and exit . Compile the .bashrc file . Type cd and . .bashrc to compile .bashrc file.
For more reference : https://pkashyap28.wordpress.com/2014/09/11/manage-multiple-grails-application-in-ubuntu/
Add a tip if you are working on Windows: there's a way for quick-changing version of GRAILS. You just need to change GRAILS_HOME & GROOVY_HOME (by script, GUI,...) then CLOSE the cmd window used to run grais-app, then start it again. By this way, the change will be applied and you can avoid restarting.
Following the #tim_yates' answer. (unix based OS).
1- Put all grails versions under opt folder:
/opt/grails-2.3.1
/opt/grails-2.5.3
/opt/grails-3.1.1
2- Download and save grails.sh in somewhere you know. (I put mine at /opt/grails-selector)
Edit your ~/.bash_profile file. The PATH var should point to the folder you put your grails.sh. And set GRAILS_HOME to your default version (in case you are creating a new project, for example, it'll use this default version unless you declare to use another.
export PATH=$PATH:/opt/grails-selector
export GRAILS_HOME=/opt/grails-3.1.9
4- You're good to go. May you need to reopen your terminal or logout-login. When you call grails it will calls the grails.sh and then it looks for the version set in your project. So you it works automatically.