本文介绍了如何将源文件夹添加到Grails应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用STS开发Grails应用程序,我需要使用wsimport实用程序生成的一堆类。为了不将自己的源代码与自动生成的源代码混合,我想添加单独的目录,并将生成的类放在那里: $ b $ > grails-project
|
| - .classpath
| - .groovy
| - .project
| - .settings
| - application.properties
| - grails-app
| - lib
| - scripts
| - src
| | - groovy
| | - java
| ` - wsimport< - 我想创建额外的源文件夹
| - target
| - target-eclipse
| - test
` - web- app

我可以将新的类路径条目添加到.classpath文件,STS将识别源文件,但是对Grails做些什么?我需要在某个配置文件中指定它吗?

解决方案

答案在这里:

http://ofps.oreilly.com/titles/9781449323936/chapter_configuration.html

总而言之,您可以使用像这样的配置:

  extraSrcDirs = [$ basedir / src / extra1,$ basedir / src / extra2,...] 

eventCompileStart = {
for(String path in extraSrcDirs){
projectCompiler.srcDirectories<<路径
}
copyResources buildSettings.resourcesDir
}

eventCreateWarStart = {warName,stagingDir - >
copyResources$ stagingDir / WEB-INF / classes
}

private copyResources(destination){
ant.copy(todir:destination,
failonerror:false,
preservelastmodified:true){
for(String in extraSrcDirs path){
fileset(dir:path){
exclude(name:'* .groovy')
exclude(name:'* .java')
}
}
}
}

这会让grails编译器知道额外的源文件夹,但我认为STS不足以知道源文件夹。为此,您将不得不继续更新项目的.classpath。


I use STS for developing Grails application, and I need to use there a bunch of classes generated by wsimport utility. In order to not to mix my source with autogenerated source, I want to add separate directory and put there generated classes, like this:

grails-project
 |
 |-- .classpath
 |-- .groovy
 |-- .project
 |-- .settings
 |-- application.properties
 |-- grails-app
 |-- lib
 |-- scripts
 |-- src
 |   |-- groovy
 |   |-- java
 |   `-- wsimport     <- where I want to make additional source folder
 |-- target
 |-- target-eclipse
 |-- test
 `-- web-app

I can add new classpath entry to .classpath file and STS will recognize sources, but what do I do to Grails? Do I need to specify it in some config file or something?

解决方案

The answer is here:

http://ofps.oreilly.com/titles/9781449323936/chapter_configuration.html

To summarize, you can use configuration like this:

extraSrcDirs = ["$basedir/src/extra1", "$basedir/src/extra2", ...]

eventCompileStart = {
   for (String path in extraSrcDirs) {
      projectCompiler.srcDirectories << path
   }
   copyResources buildSettings.resourcesDir
}

eventCreateWarStart = { warName, stagingDir ->
   copyResources "$stagingDir/WEB-INF/classes"
}

private copyResources(destination) {
   ant.copy(todir: destination,
            failonerror: false,
            preservelastmodified: true) {
      for (String path in extraSrcDirs) {
         fileset(dir: path) {
            exclude(name: '*.groovy')
            exclude(name: '*.java')
         }
      }
   }
}

This will let the grails compiler know about the extra source folders, but I don't think it is enough for STS to know about the source folders. For that, you will have to continue updating the project's .classpath.

这篇关于如何将源文件夹添加到Grails应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:08