With Struts2 we have to have struts.xml in the class path, so it no longer works to have it under WEB-INF. So the way I got my project to deploy was to stick it under WEB-INF/classes and have it include ../struts2.xml
2 Problems:
Eclipse cleans out the classes folder when I do a rebuild, so it
deletes struts.xml
Eclipse doesn't show the classes folder in my project browser, so
its a poor place to stick config files in the first place.
How are you Struts2 Eclipse developers doing this?
You can either just put the struts.xml at the root of your source directory or set up an additional resources source directory and put it there. Eclipse quite happily copies it to WEB-INF/classes for you when it does a compilation.
I am late to the party, we can configure the struts.xml in any directory in the classpath of the web application, but provide the location using the "config" init parameter of the filter configuration in web.xml as below, if my struts.xml file is in "/com/resources/" directory.
<filter>
<filter-name>action</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,/com/resources/struts.xml</param-value>
</init-param>
</filter>
If we don't provide a config init parameter struts2 by default takes 3 values "struts-default.xml,struts-plugin.xml,struts.xml", you can see the struts2 Dispatcher class code below which will configure these 3 files to the configuration manager.
String configPaths = (String)this.initParams.get("config");
if (configPaths == null) {
configPaths = "struts-default.xml,struts-plugin.xml,struts.xml";
}
String[] files = configPaths.split("\\s*[,]\\s*");
for (String file : files)
if (file.endsWith(".xml")) {
if ("xwork.xml".equals(file))
this.configurationManager.addContainerProvider(createXmlConfigurationProvider(file, false));
else
this.configurationManager.addContainerProvider(createStrutsXmlConfigurationProvider(file, false, this.servletContext));
}
With Struts 1.2, it was required to put the struts-config.xml in the classpath (under WEB-INF folder) but with Struts 2.0, it is required to be in src/main/resources folder.
See the documentation Struts 2 Documentation here
I pasted struts.xml in this directory and the project executed fine.
I am not using Eclipse so this answer is not specific to your requirements but, I use Maven so we have all the "resources" that are needed by the application in a seperate folder called "resources" and When the application is built these files are copied into the appropriate places automatically. In Netbeans the files in the folder are available and I know that there are persons using eclipse with a similar setup.
I should point out that our project started from appfuse so most of these configurations were pre made. You can look at how it was done there.
In struts 2 projects, struts.xml file is added in src(Java Resources) folder along with the packages and libraries.
Please refer the image given below.
If u want to know more about struts 2 project structure please visit this link
Note: In eclipse, you are not allowed to paste a file directly in src folder. So you need to first paste it in any other place in the project( for example, in 'WebContent' folder), then use move functionality to put it in right place( That is 'src' folder).
You can place struts.xml file in src(Java Resources) packages.
When the compilation process struts.xml file will generate inside the ROOT/WEB-INF/classes directory.
if you get the same error again and again better check the struts actions.
check the deployed path of the application and you can find out what you want.
(struts.xml file)
Related
I have confusion about these files in struts2.
Normally struts.xml file the core which has configuration in struts1. So I also thought of using struts.xml file.
But in my project already they put struts2-config-browser-plugin.jar, it has struts-plugin.xml. Just searched in Google and found that struts-plugin.xml is enough to run struts application.
Now I'm adding the struts.xml file, the application is not working.
Can I use both XML file in application?
If I remove the struts2-config-browser-plugin.jar , what are the changes need to add in struts.xml file ?
There are three configuration files which are by default loaded by the framework (if they exist):
struts-default.xml - included in struts2-core.jar, contains all basic configuration of the framework
struts-plugin.xml - if plugin want to override some defaults or define its own settings (results, actions, etc)
struts.xml - contains user defined configuration, mostly actions, results and custom stacks of interceptors
You should just use struts.xml and put all the configurations there.
Some notes about struts-plugin.xml - http://struts.apache.org/development/2.x/docs/plugins.html
We are using various plugins in our grails application (like logging, spring security core, ui, acl and many others). Now these plugins come with default gsps (in the views folder of each plugin).
I want to build a WAR without including the views of any plugin. So when the war is built right now it creates the plugins folder which contains views folder which come by default with the plugin, these views are introducing a lot of vulnerabilities and so I want to exclude the plugins views.
I am trying this right now in BuildConfig.groovy like below:
grails.project.dependency.resolution = {
grails.war.resources = { stagingDir ->
println "Customized delete started..."
delete{fileset dir: "${stagingDir}/WEB-INF/plugins/logging-0.1/grails-app/views/"}
delete{fileset dir: "${stagingDir}/WEB-INF/plugins/spring-security-ui-0.1.2/grails-app/views/"}
}
}
But the problem is the code tries to delete the views when they are not yet created by the war building process. Hence I get a file not found error for those plugins views.
Where should I write the code to delete the plugins views so that they are already created and available to delete when building the WAR, or how do I not include the plugins views in the WAR?
Thanks in advance..
Priyank
I answered this question on the Grails mailing list.
http://grails.1312388.n4.nabble.com/deleting-plugins-views-gsp-when-building-the-war-td4560517.html
(The answer hasn't yet shown up in nabble)
You can remove/add files from/to a war file in the eventCreateWarStart
event specified in scripts/_Events.groovy file.
This might work:
filename: scripts/_Events.groovy
eventCreateWarStart = { warName, stagingDir ->
Ant.delete(dir: "${stagingDir}/WEB-INF/plugins/logging-0.1/grails-app/views")
Ant.delete(dir: "${stagingDir}/WEB-INF/classes", includes:"gsp_logging*.*")
Ant.delete(dir: "${stagingDir}/WEB-INF/plugins/spring-security-ui-0.1.2/grails-app/views")
Ant.delete(dir: "${stagingDir}/WEB-INF/classes", includes:"gsp_springSecurityUi*.*")
}
I'm not sure if you could also remove plugin Controller classes without problems. We've used Filter classes to "disable" controllers provided by plugins.
As a side-note you can disable "development-only" plugins in the production environment by using the yet undocumented "grails.plugins.excludes" feature:
Example:
in Config.groovy:
import grails.util.Environment
if(Environment.current == Environment.PRODUCTION) {
grails.plugin.excludes = ['somePluginName']
}
I'm unable to pack taglibrary in a war file. I moved tags from project to extra library the current project is depending now. I put the taglibrary file into the META-INF directory of the jar containing tags (how is described here). But the page does not work:
Expression Error: Named Object: eu.barbucha.barbatag.simple.PropertyTag not found.
The server is able to find the taglibrary. Otherwise the page works, just one waring appears:
Warning: This page calls for XML namespace http://barbucha.eu/tags declared with prefix br but no taglibrary exists for that namespace.
Thus the question is: Why the server finds just the descriptor, but not the classes? When I copy classes from WEB-INF/lib/barbatag.jar into WEB-INF/classes and restart the webapp in administration console, the page gets working. The server also finds UI-components only if they are involved directly in classes of the applictation, but not in the jar stored in the WEB-INF/lib directory. On other hand the server loads taglib descriptor from the jar. It's really confusing... Declaration of the critical class:
package eu.barbucha.barbatag.simple;
#FacesComponent("eu.barbucha.barbatag.simple.PropertyTag")
public class PropertyTag extends UIComponentBase { ... }
Definition of critical tag:
<tag>
<display-name>The component taking values from a property file</display-name>
<tag-name>property</tag-name>
<component>
<component-type>eu.barbucha.barbatag.simple.PropertyTag</component-type>
</component>
</tag>
One potentionally important point: I'm using Spring MVC.
You need to supply a /META-INF/faces-config.xml file in the JAR in order to get JSF to scan the JAR file for classes with JSF specific annotations like #FacesComponent. This is done so to prevent JSF from unnecessarily scanning every single JAR file for classes (which might be very time and CPU consuming if you have lot of them).
I am using JSR 303 Bean validation in my JSF 2.0 web application and it works fine with annotations. Now I would like to ignore annotations and configure validation rules using the validation.xml file, so this is what I did (I am using an eclipse dynamic web project) :
Added validation.xml under WebContent/META-INF/validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
>
<constraint-mapping>META-INF/validation/constraint-mapping.xml</constraint-mapping>
</validation-config>
Then created the file constraint-mapping.xml under WebContent/META-INF/validation/constraint-mapping.xml
<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
<bean class="my.full.path.ValidationMB" ignore-annotations="true">
</bean>
</constraint-mappings>
Having these configurations in place, I suppose the annotations in my bean class ValidationMB shall be ignored, BUT this is not happening!, which makes me assume that the validation.xml file is not being loaded.
any ideas? thanks.
Environment:
Apache Tomcat 7.0.23
javax.faces-2.1.4.jar
hibernate-validator-4.2.0.Final.jar
hibernate-validator-annotation-processor-4.2.0.Final.jar
validation-api-1.0.0.GA.jar
slf4j-api-1.6.1.jar
From the spec: section 4.4.6. XML Configuration: META-INF/validation.xml
Unless explicitly ignored by calling
Configuration.ignoreXMLConfiguration(), a Configuration takes into
account the configuration available in META-INF/validation.xml. This
configuration file is optional but can be used by applications to
refine some of the Bean Validation behavior. If more than one
META-INF/validation.xml file is found in the classpath, a
ValidationException is raised.
To solve my problem I had to create a META-INF folder under the project src folder, which ends in the WEB-INF/classes/META-INF.
The structure of the web application is:
ROOT
|_META-INF -- don't put validation.xml here
|_WEB-INF
|__ classes
|_META-INF
|__validation.xml
But I think that if I pack my web application in a jar file and reuse it in another project It may not work, I will let you know later once I do it.
Try to put your validation.xml directly into the WEB-INF/ directory.
I stumbled across this while looking for something else but wanted to clarify to the OP what is happening. You do in fact need the file to exist at META-INF/validation.xml; however, that is relative to the classpath which is why it worked when you put it under WEB-INF/classes/META-INF/validation.xml.
The cleaner approach is to let the file be put there for you. Your Eclipse project should already be outputting whatever is in your source directory to WEB-INF/classes somehow for you or nothing would be running. But sometimes there are filters on what it outputs so it might excluding something. You might want to check your src dirs and make sure they don't have exclusions.
Just as an example, if you had a Maven war project, all of your java sources would go in src/main/java and the generated classes would end up in the WEB-INF/classes directory. The equivalent happens for src/main/resources which contains non-source files. When I want *.xml, *.properties, etc. to end up in WEB-INF/classes I put them in src/main/resources. For your example I would have a src/main/resources/META-INF/validation.xml file.
Hope this helps anyone else who comes across this and is confused.
I have a JAR in my lib folder of the project and trying to get the directory structure that contains property files on the classpath when building using ANT. Any ideas how best to the get that structure on the classpath?
Thanks!
I'm assuming you want to load a properties file into your build using the property task.
If this is the case, there are a couple of options.
First you could use the url form of the task, using a jar url:
<property url="jar:file:lib/my_jar.jar!/path/to/myfile.properties" />
Alternatively you could use the resource form, and specify the jar as the classpath:
<property resource="/path/to/myfile.properties" classpath="lib/my_jar.jar"/>
If it's something else you want to do rather than load the properties, look into javaresource - many tasks are able to take a resource as input so you should be able to find a way to do what you want.