maven-war-plugin copying overriden directory to final artifact - maven-3

We're using maven-3.3.9 with maven-war-plugin to generate my final war. We were having problems with out static files when they were changed because browser was using the cached version.
So we decided not to use query string version attribute after referecing those static files. Our choice was to generate our static files directories overriden the way the maven-war-plugin states in Adding and Filtering External Web Resources docs, section Overriding the default destination directory.
Here's how we done it:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webResources>
<webResource>
<directory>src/main/webapp/WEB-INF/resources</directory>
<targetPath>WEB-INF/resources/${parsedVersion.majorVersion}${parsedVersion.minorVersion}${parsedVersion.incrementalVersion}${buildNumber}</targetPath>
<filtering>true</filtering>
</webResource>
</webResources>
</configuration>
</plugin>
We're also using another plugins to get the project version parsed and number revision also, but they're not important to this question.
The problem is that the static files directories are created correctly as we expected but its contents are also created in the regular way like we're not using webResources instructions, so I get my resources contents dir twice. I get resources dir with the dir I want and all dirs inside of this second dir are also in resources dir as sibblings of it. How can I generate the resource dir as it is doing now and not duplicating its contents?
My final output is something like below:
|--- resources
|--- js
|--- css
|--- fonts
|--- js
|--- myoverridendir
|--- js
|--- css
|--- fonts
|--- js

Because the same folder is coming from two resource directories
Through src/main/webapp as it is warSourceDirectory
It is specified as a resource in webResources
As you want only one copy, the one coming from webResources, the one coming from src/main/webapp need to be excluded. It can be done using <warSourceExcludes> tag.
For example, let us say js is one such folder inside src/main/webapp folder. It can be excluded using <warSourceExcludes>js/</warSourceExcludes>

Related

relative path to imported file in LaTeX

I am currently reworking a set of slides to teach students at an university, of course the files are written in LaTeX. Too increase modularity, I want to include files relative to a base file, which will be imported by other files. So suppose I have the following structure:
|-- document.tex
`-- module
`-- a
|-- base.tex
`-- listings
`-- test.java
Now I want to import test.java inside base.java by referring to the relative path listings/test.java. Is there a way to then import base.tex into document.tex? Or can I at least extend the relative path listings/test.java to the new parent document document.tex, e.g. module/a/listings/test.java?
I am displaying listings by using minted which is unfortunately not affected by the import package.
I have figured it out.
To effectively recreate the secret principle of OOP you have to use the package currfile which has the \currfiledir command, which is like pwd in bash.
It only works in via \input or \include loaded files, not by using import or anything else. It also does not work with the fragile option activated.
In this manner, you may create a module, which is relative to it's base file, not the one your document starts in.

phpspec tests within zend 2 module

I'm trying to move my spec folder into a zend 2 module folder. I don't totally understand how phpspec determines where the source folder is. How can I configure it to use the below folder structure.
\ModuleName
\spec
\ModuleName
\Class.php
\src
\ModuleName
ClassSpec.php
...
...
You can configure spec and src paths, see the docs:
http://phpspec.net/en/latest/cookbook/configuration.html
If that doesn't solve your issue, you'll need to write a phpspec extension and provide a custom resource locator. Here's a similar example for Symfony:
https://github.com/phpspec/Symfony2Extension/blob/master/src/PhpSpec/Symfony2Extension/Locator/PSR0Locator.php

Facelet Tag Library mechanism does not work as expected

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).

bean-validation validation.xml ignored

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.

Where to put struts.xml

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)

Resources