2

I am a grails programmer and I want to remove the unnecessary jar files that are included in the war file. There are so many unnecessary jar files included in the war file. Is there any quick solution to do so? Also can you mention the jar files which are necessary to make and run the simple grails war.

Biswas
  • 598
  • 2
  • 16
  • 34
  • 1
    Can you give an example of an "unnecessary jar file"? Without knowing what you mean by that it's hard to answer your question. I mean, you could use grails prod war -nojars to exclude all jar files and create a "skinny war" file but that doesn't include ANY jar files. – Joshua Moore Jul 18 '14 at 17:16
  • I dont have any database in my project so i deleted my datasource file. Now I want to remove h2 and hibernate jar. But when I remove them, it throws error. So I only want to include the minimum jar file that are required to run my project. Do you have a list of the jar files that are required to run my project. Thanks – Biswas Jul 19 '14 at 05:14

1 Answers1

0

You can exclude unnecessary jar from war by adding following lines in BuildConfig.groovy.

grails.war.resources = { stagingDir ->
  delete(file:"${stagingDir}/WEB-INF/lib/jarFileName.jar")
}

Example : Removing hibernate core

grails.war.resources = { stagingDir ->
  delete(file:"${stagingDir}/WEB-INF/lib/hibernate-core-3.3.1.GA.jar")
}
Ramsharan
  • 2,054
  • 2
  • 22
  • 26
  • Hi Ramsharan, I tried this but when i remove h2 and hibernate jar, it throws error on deployment. Do you by any chance have a list of jar files that are necessary to the deployment. Thanks – Biswas Jul 19 '14 at 05:20
  • Can you please provide the error stacktrace? How do you deploy the application, by using command run-app or run-war or in separate tomcat? I have never listed minimal jar files that are necessary for deployment – Ramsharan Jul 19 '14 at 15:32
  • I have deployed in tomcat and used the command run-war. In run-app everything is fine. The stacktrace is: 2014-07-22 21:55:17,454 [localhost-startStop-1] ERROR context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Entity at java.util.concurrent.FutureTask.run(FutureTask.java:262) – Biswas Jul 22 '14 at 16:14
  • 1
    This construction works. I was able to remove unwanted jars from the war using this method. – augustearth Apr 01 '16 at 16:46