我们正在维护一个用Grails 1.3.9开发的网络应用程序。
为了监控性能,该应用程序安装了grails-melody 1.21插件。
似乎这个插件在grails 1.3. x的存储库中不再可用。我按照留档中的建议从google-code下载了它。
stackoverflow中的另一篇文章建议可以将压缩的插件放在lib中,然后从BuildConfig. groovy中引用。
plugins {
runtime ":hibernate:1.3.9"
build ":tomcat:1.3.9"
compile ":dojo:1.6.1.17"
// Downloaded from
// https://code.google.com/p/javamelody/downloads/list?can=1&q=grails
// Installed from lib
// https://stackoverflow.com/questions/15751285/whats-the-correct-way-to-install-a-grails-plugin-from-a-zip-file
compile ":grails-melody:1.21"
}
我这样做了,这个过程在使用OracleJDK7(在Ubuntu 14.04上)构建war文件时工作得很好。我不得不将grails-grails-melody-1.21.zip重命名为grails-melody-1.21.zip以便找到它。
$ java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
在构建过程中,melody的依赖项在构建过程开始时加载,而grails文件也是副本:
...
Downloading: /home/matejk/devel/grails/grails-1.3.9/lib/servlet-api-2.5.jar ...
Download complete.
Downloading: /home/matejk/devel/grails/grails-1.3.9/lib/jsp-api-2.1.jar ...
Download complete.
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.pom ...
Download complete.
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.pom.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.pom ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.pom.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.pom ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.pom.sha1 ...
Download complete.
Downloading: /home/matejk/devel/grails/grails-1.3.9/lib/groovy-all-1.7.8.jar ...
Download complete.
Downloading: /home/matejk/devel/grails/grails-1.3.9/lib/commons-beanutils-1.8.0.jar ...
Download complete.
...
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.jar ...
Download complete.
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.jar.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.jar ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.jar.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.jar ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.jar.sha1 ...
Download complete.
Downloading: /home/matejk/devel/grails/grails-1.3.9/lib/aspectjweaver-1.6.8.jar ...
...
结果的war文件在WEB-INF/lib中有javamelody、jrobin和itext jar。
但是,要求是在另一台机器(Jenkins)上使用JDK1.6构建应用程序,在这台机器上,每次构建都要完成源的干净签出。
java -version
java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1ubuntu1)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
下载jar发生在构建过程的后期:
Executing hibernate-1.3.9 plugin post-install script ...
Plugin hibernate-1.3.9 installed
Installing zip /var/lib/jenkins/.ivy2/cache/org.grails.plugins/grails-melody/zips/grails-melody-1.21.0.zip... ...
[mkdir] Created dir: /var/lib/jenkins/workspace/etermin-2.4/target/projects/etermin-2.4/plugins/grails-melody-1.21
[unzip] Expanding: /var/lib/jenkins/.ivy2/cache/org.grails.plugins/grails-melody/zips/grails-melody-1.21.0.zip into /var/lib/jenkins/workspace/etermin-2.4/target/projects/etermin-2.4/plugins/grails-melody-1.21
Installed plugin grails-melody-1.21 to location /var/lib/jenkins/workspace/etermin-2.4/target/projects/etermin-2.4/plugins/grails-melody-1.21. ...
Resolving plugin JAR dependencies ...
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.pom ...
Download complete.
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.pom.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.pom ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.pom.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.pom ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.pom.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.jar ...
Download complete.
Downloading: http://repo1.maven.org/maven2/net/bull/javamelody/javamelody-core/1.44.0/javamelody-core-1.44.0.jar.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.jar ...
Download complete.
Downloading: http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.jar.sha1 ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.jar ...
Download complete.
Downloading: http://repo1.maven.org/maven2/org/jrobin/jrobin/1.5.9/jrobin-1.5.9.jar.sha1 ...
Download complete.
但是,当使用该JDK创建war时,javamelody、jrobin和itext jar不会被打包。
因此,webapp的部署和启动失败。
SEVERE: Error configuring application listener of class net.bull.javamelody.SessionListener
java.lang.ClassNotFoundException: net.bull.javamelody.SessionListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4153)
谢谢,
马泰
编辑:删除~/. grails/1.3.9/中的grails文件后,JDK6和JDK7的行为是相同的:
jar文件未打包,部署失败。
我在Grails 1.3.7中集成另一个插件时遇到了同样的问题
我知道我所说的不是最佳实践,但是我做了这个变通方法。
将插件的. zip放在项目中所需的文件夹中,然后提交到svn repo中。
在本地环境中之后,您可以使用grails install Plugin脚本指定要安装的插件。
当您需要在其他机器上构建应用程序时,您还可以在项目中放置一个用户可以调用的脚本。该脚本将首先包含grails install Plugin,然后包含grails war命令。
另一种方法是,如果您已签出插件的所有soce代码,例如在名为myPlugin的文件夹(名为my-plugin)中,并且您的项目位于文件夹myProgect中,并且每个文件夹都在同一目录中,您可以在BuildConfig. groovy中添加一行代码:
grails.plugin.location.'my-plugin' = "../myPlugin"
很明显,如果插件文件夹不在同一个路径中,您可以放置正确的路径:
grails.plugin.location.'my-plugin' = "../path/to/plugin/myPlugin"
这种方式不需要调用install plugin方法,grails知道依赖并打包插件。
希望我能帮助你,最好的问候。
您可以设置一个本地存储库管理器,例如ArtiFactory,并从该存储库下载Grails插件。
您可以为Grails插件创建一个本地的艺术家库,在Grails插件存储库中不可用,并部署1.21版本的JavaMelody Grails插件。
接下来您需要将此本地存储库添加到Grails正在解析的存储库列表中(BuildConfig. Groovy):
groovy grails.project.dependency.resolution = {
...
repositories {
grailsPlugins()
grailsHome()
mavenRepo "http://localhost:8081/artifactory/grails-plugins-local/"
grailsCentral()
}
plugins {
build ":grails-melody:1.21"
}
...
}
查看spring.io博客中的使用Grails 1.3管理插件,了解有关此类解决方案的更多详细信息。
我设法解决这个问题的方法是将melody的deps显式包含到BuildConfig. groovy(从插件的依赖项复制):
dependencies {
// Deps for grails-melody (copied from plugin deps) that are *not* included automatically with plugin.
compile "net.bull.javamelody:javamelody-core:1.44.0"
compile ("com.lowagie:itext:2.1.7") {
excludes "bcmail-jdk14", "bcprov-jdk14", "bctsp-jdk14"
}
compile "org.jrobin:jrobin:1.5.9"
}
plugins {
compile ":grails-melody:1.21"
}
我在Grails JIRA中看到了一些可能与我所经历的有关的错误,并在2. x中得到解决
https://jira.grails.org/browse/GRAILS-7608