当我创建一个 Grails 应用程序时,它在 web-app
中带有一些默认文件。目录:
$ 查找网络应用程序
网络应用
网络应用程序/CSS
网络应用程序/css/errors.css
网络应用程序/css/main.css
网络应用程序/css/mobile.css
网络应用程序/图像
网络应用程序/图像/apple-touch-icon-retina.png
网络应用程序/图像/apple-touch-icon.png
网络应用程序/图像/favicon.ico
网络应用程序/图像/grails_logo.jpg
网络应用程序/图像/grails_logo.png
网络应用程序/图像/leftnav_btm.png
网络应用程序/图像/leftnav_midstretch.png
网络应用程序/图像/leftnav_top.png
网络应用程序/图像/皮肤
网络应用程序/图像/皮肤/database_add.png
网络应用程序/图像/皮肤/database_delete.png
网络应用程序/图像/皮肤/database_edit.png
网络应用程序/图像/皮肤/database_save.png
网络应用程序/图像/皮肤/database_table.png
网络应用程序/图像/皮肤/exclamation.png
网络应用程序/图像/皮肤/house.png
网络应用程序/图像/皮肤/信息.png
网络应用程序/图像/皮肤/shadow.jpg
网络应用程序/图像/皮肤/sorted_asc.gif
网络应用程序/图像/皮肤/sorted_desc.gif
网络应用程序/图像/spinner.gif
网络应用程序/图像/springsource.png
网络应用程序/js
网络应用程序/js/application.js
(META-INF
和 WEB-INF
从输出中截取的文件夹)
这些文件在我的应用程序中造成困惑,并且还使用常见的目录名称 css
, images
, 和 js
,我可能想将其用于我自己的资源。
过去我手动删除了这些,但运行后它们会自行返回 grails upgrade
,在此过程中覆盖我自己的文件。
我看不出有任何理由保留这些文件。有什么我想念的吗?如果没有,我怎样才能摆脱它们并确保它们永远不会回来?
最佳答案
根据Burt Beckwith , 正确的解决方法是不使用 grails upgrade
.显然,这不再是升级 Grails 应用程序的推荐方式,因为它实际上只做了两件重要的事情,那就是升级版本,然后清理应用程序,以便重新下载所有内容。
小升级
从该帖子中,较小版本更改的推荐过程是:
- Edit
application.properties
and update the version.- Then run
grails clean
to clear outdated files.- Finally run
grails compile
and it'll ask you if you want to upgrade the Hibernate and Tomcat plugins (if they're listed inBuildConfig.groovy
).You can also manually delete the old plugins in the work folder under the
$HOME/.grails
folder.
Burt 提供的另一个提示是:
It's even simpler if you add
grails.project.work.dir = 'target'
toBuildConfig.groovy
. Then all your plugins will be there and you can just delete the whole target folder and all the plugins will be reinstalled and/or updated, and all the classes will be recompiled.
重大升级
主要更新(例如将 1.x 应用程序升级到 2.x 应用程序)的过程涉及更多一点:
- create a new empty app in the new version of Grails
- create a new empty app in the old version of Grails
- diff your current app with the empty old-version app - this will tell you what you deleted, added, and changed. Copy new files over, delete stuff that should be deleted, and re-do the changes you made. Be sure to read the release notes and upgrade information for the intermediate Grails versions so you know how to make the new changes - e.g. HSQLDB -> H2 in DataSource.groovy, etc. Don't just blindly make the same changes.
希望这最终会记录在官方文档中,因为这是有道理的,因为升级过程太复杂而无法有效地自动化。
新应用
然而,这并没有解释如何处理新的应用程序。当然,您可以简单地删除所有 Grails 特定的文件(除非您使用脚手架,否则我建议您这样做)。
另一种选择是将所有 Grails 特定文件移动到某个子目录中,然后手动修改(和/或重命名)
main
布局、CSS 文件和资源链接指向这些新位置。如果你还想使用脚手架,我建议复制
main.gsp
布局到 scaffolding.gsp
,并为包含所有默认 CSS 和 JS 要求的脚手架创建一个新的资源模块。然后运行 grails install-templates
,它将为您提供脚手架的基本 View 模板。然后,您可以轻松更改布局并添加或更新正确的资源模块。最后,一旦您以您想要的方式获得了基本应用程序,请将其压缩并保存以备后用。这至少是一种简单的方法,只需要做一次。
Note
After installing the templates, you probably won't need theartifacts
orwar
template folders, located undersrc/templates
. Unless you know you use them, they should be deleted.
最后一点,请确保您使用良好、强大的版本控制系统,例如 git 或 mercurial。如果您不小心运行了
grails upgrade
,这将很容易查看已修改的内容。 ,并丢弃或回滚您不想更改的文件。使用不错的 IDE 或 GUI,您通常只需单击几下即可解决此问题。
关于grails - 如何永久删除默认的 Grails web-app 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11481049/