What is the right way to package Struts2 jar files? - struts2

We encountered the problem while upgrading to Struts2 from Struts1
Our application has .ear with .war file inside. Plus we have another separate .war file.
We were able to upgrade and deploy .ear file with Struts2.
Hovewer when we tried to deploy second .war file we get the error:
Unable to load configuration. - bean - app-config.war/WEB-INF/lib/struts2-core-2.3.15.1.jar/struts-default.xml:29:72 ...
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean
Both war files have required struts2 .jar files.
Then we tried to pull Struts2 .jar files out of .war to JBoss lib directory. JBoss AS run fine but first call to jsp page threw error:
Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: File "/struts-tags" not found
We also tried to create shared .war file that contained only struts2 jar files. We get the same error:
Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: File "/struts-tags" not found
Each .ear and .war files run fine when they deployed alone without each other.
Please advice what is the right way to package Struts2 jar files when application has .war and .ear files.
Thank you,
Yuri

Related

How to exclude grails plugin jar from war file

Grails 3.2.5. Build.gradle has mail plugin:
compile "org.grails.plugins:mail:2.0.0.RC6"
In deploying a war to production I need to remove javax.mail-1.5.6.jar from WEB-INF/lib since that jar must be in the Tomcat lib when using a JNDI mail resource. So how do I keep the mail plugin but remove the offending jar file from the war? I knew how to do this in Grails 2.x. Via the gradle war task in build.gradle I have tried to exclude the file (doesn't work - the jar drifts in from a plugin somehow), and have tried to filter the file out. When I build the war I get two files - "app-0.1.war" and "app-0.1.war.original". The "original" file has the WEB-INF/lib/javax.mail jar filtered out, but the real, complete war still has it.
So how do I prevent that plugin jar from getting into the war file? Thanks.
One way to do it is with something like this:
war {
rootSpec.exclude '**/javax.mail*.jar'
}
(you may need to adjust depending on whether or not you want to also exclude the javax.mail-api jar file along with the javax.mail jar)
See https://github.com/jeffbrown/excludejar/blob/67734ac0c65cdbead468f1e65bcfc29041cd2279/build.gradle#L70-L72

Create war file in grails using GGTS

I have done a small application in Grails, and now I need to generate a war file to test it on server. I generated a war using command grails:war. It has generated the file but named it as myapp-01.war. I don't want this, I need a war where the file name should be same as the project; like myapp.war
Try:
grails war myapp.war
Additional options: http://docs.grails.org/3.1.1/ref/Command%20Line/war.html

Grails 3.1.5 dont produces jar file

In version to 3.1.5, the command "package" not produces a jar file in "project/build/libs"
I ran a simple "create-app" and "package" with versions 3.0.9 and 3.1.5. Only the first produces a jar file. No error appears in both.
Someone knows how I create a executable JAR, in version 3.1.5?
The documentation states...
If you prefer not to operate a separate Servlet container then you can
simply run the Grails WAR file as a regular Java application.
And then provides the following example:
grails war
java -Dgrails.env=prod -jar build/libs/mywar-0.1.war
So basically, the generated war file is a jar file.

slf4j version mismatch when using grails 1.3.7 with quartz scheduler 1.0-RC1

My application uses grails 1.3.7 with quartz scheduler 1.0-RC1 plugin. It runs fine locally on tomcat when I run it using grails run-app. However, when I create a war file using grails prod war and deploy it in WebLogic, I'm getting the below error:
SLF4J: The requested version 1.5.8 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
log4j:ERROR Error initializing log4j: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.trace(SLF4JLocationAwareLog.java:107)
at org.apache.commons.beanutils.BeanUtilsBean.convert(BeanUtilsBean.java:1073)
I figured this is because grails 1.3.7 uses slf4j 1.5.8, but the quartz plugin uses 1.6.0 and hence there's a conflict. I tried to address it by excluding the slf4j-api jar in BuildConfig.groovy like:
plugins {
compile(":quartz:1.0-RC1") { excludes "slf4j-api" }
}
I was hoping the above config entry would prevent slf4j 1.6.0 from being downloaded and resolve the conflict. But it isn't. When I run grails dependency-report, I still see the conflict and I'm unable to deploy the application in WebLogic.
EDIT: Screenshot of the conflict from grails dependency-report:
Any pointers to resolve this?
You have conflict of jar file. Weblogic comes with sl4j by default and your war file should also contain sl4j jar file inside WEB-INF\lib folder. You can try changing class loading to parent last from admin console.
I resolved this issue by using the code below in BuildConfig.groovy to exclude slf4j-api-1.6.0.jar from the packaged war. The suggestion was posted here
grails.war.resources = { stagingDir ->
delete(file:"${stagingDir}/WEB-INF/lib/slf4j-api-1.6.0.jar")
}
I also had to add slf4j-api-1.5.8.jar to the project's lib folder.

Referencing external dependencies in GGTS by convention

How do I reference a dependency by convention within my project build path? Allow me to elaborate...
I'm using the Groovy/Grails Tool Suite (GGTS 3.0). I'm referencing the dependency as such in my BuildConfig.groovy:
dependencies {
compile 'tgt:jaxb-utils:1.0'
}
The referenced jar file is successfully pulled down from the Artifactory repo - I can find the jar file on my local file system in the Ivy cache. When I run any grails targets (grails compile, grails run-app, grails run-tests), it works fine - meaning my code that imports the classes from the jar has no problems. When I run grails war, the referenced jar file is packed into the constructed war.
However, and here is the crux of this post - the project build path does not reference this jar file by default or convention, so my java or groovy code that imports the classes from the jar file reports a unable to resolve class ... error.
One solution is to simply add the jar file to the lib folder and update the build path accordingly, or modify the build path to reference the jar file in the Ivy cache folder. However, I'd have to do this for any/all dependencies pulled down in this way. Any jars in the lib folder will get saved to the team source code repository, and that seems like wasted space since the grails commands work fine with just the dependency reference in BuildConfig.groovy.
Am I just being too idealistic (ie - difficult) here, or is there a better way to clean up the unable to resolve class ... errors in my IDE without having to manually add the dependent jar files to my lib folder and update my build path? Ideas?
Eclipse / STS / GGTS : If you have Grails plugin installed, you can do the following :
Right click on your project -> Grails Tools -> Refresh dependencies (or shortcut "Alt+G, R")

Resources