appengine-application.xml fails XML validation - eclipse

I have followed the instructions for configuration of multi-module appengine projects here:
https://cloud.google.com/appengine/docs/standard/java/configuration-files
I copied the appengine-application.xml directly from the example provided, changing only the project name to use a Maven property. The file looks like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<appengine-application xmlns="http://appengine.google.com/ns/1.0">
<application>${appengine.app.name}</application>
</appengine-application>
My appengine-application.xml file is located in the following directory structure:
projectname-backend/
src/...
pom.xml
projectname-common/
src/...
pom.xml
projectname-ear/
src/
main/
application/
META-INF/
appengine-application.xml
application.xml
MANIFEST.MF
pom.xml
projectname-frontend/
src/...
pom.xml
Even after cleaning the project, Eclipse is throwing this validation error for the file:
cvc-elt.1: Cannot find the declaration of element 'appengine-application'.
Other files, particularly application.xml in the same directory, are fine. So it seems to be namespace issue but I can't find any information on what it should be - this is current example in the Google doco.
Any ideas?

Related

JBoss EAR deployment fails because WAR classes are unable to find jars from EAR/lib folder

I am using JBoss EAP 7 and want to deploy an EAR file in standalone mode (using standalone-ha.xml).
I went through almost everything available on StackOverflow/JBoss forums but couldn't make my deployment to work (correctly). I have followed the docs to the best of my abilities but still the deployment of EAR gives Exception on console because the jar files inside WAR/WEB-INF/lib are not able to see the jar files present int EAR/lib folder. I can't figure out what I am doing wrong.
Structure
myEAR.ear
|- lib (contains a.jar)
|- META-INF
|--- maven (folder with pom)
|--- application.xml
|--- jboss-deployment-structure.xml
|--- MANIFEST.MF
|- myWar.war
|--- WEB-INF
|----- lib (contains b.jar)
|----- jboss-deployment-structure.xml (which should be ignored per the docs)
|----- (WEB-INF contains other files/folders such as classes,jsp etc
EAR- application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
<display-name>myear</display-name>
<module>
<web>
<web-uri>myWAR.war</web-uri>
<context-root>/mywar</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
EAR- jboss-deployment-structure.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<dependencies>
<module name="com.organization.global" export="true" />
</dependencies>
</deployment>
<!-- Having/Not having below sub-deployment has no effect -->
<sub-deployment name="myWAR.war">
<dependencies/>
</sub-deployment>
</jboss-deployment-structure>
Deployment succeeds if I copy a.jar inside WAR/WEB-INF/lib/ folder, otherwise gives an exception: Caused by: java.lang.NoClassDefFoundError related to a class specific to a.jar. I want my WAR to be able to get access to all the jars put together inside EAR/lib.
I read in one of the forums that the jar/classes in lib folder should be available to all modules within the EAR but sometimes they are not added automatically but I couldn't find the solution on how to add them.
Any guidance would be appreciated. Thanks in advance!
In JBoss EAP 7, to access lib files present in ear inside war you could try by adding a context param in your war's web.xml.
To create env variable try below in terminal:
export JAR_HOME=../jboss-eap-7.1/standalone/deployments/example.ear(Please add value equivalent to your environment and ear's path)
export PATH=$PATH:$JAR_HOME
Add this variable to web.xml as file:${JAR_HOME}/lib/example.jar
Read this context param inside your classes present inside war.

Copy files to new project and now cannot create JDBC driver of class '' for connect URL 'null'

Caused by: java.sql.SQLException: No suitable driver
A Maven project in eclipse, I lost the .project file for this application. I have to copy the files into another project. So it was running before.
I am using a DataSource in Tomcat. The projects META-INF/context.xml file hasn't changed. It's deployed into /META-INF directory. web.xml and pom.xml is the same. I don't know what has changed. mysql-connector-5.1.38.jar is in $Catalina/lib.
I would look at the Build Path and Deployment Assembly but let me know.
build path.
deployment assly.
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/widget"
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="3"
maxWait="10000"
username="appuser"
password="appuserpass"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/widget"/>
</Context>
web.xml
<resource-ref>
<description>MySQL Datasource</description>
<res-ref-name>jdbc/widget</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Coming back to this, I saw a similar project and matched the deployment assembly. This seemed to fix the issue. Current configuration :
/src/main/java -> WEB-INF/classes
/src/main/resources -> WEB-INF/classes
/src/main/resources/META-INF -> META-INF
/src/main/webapp -> /
/src/test/java -> WEB-INF/classes
Maven Dependencies -> WEB-INF/lib

"No such file:" error in jenkins when integrating with Maven build

I have recently started using Jenkins as a CI tool for my Maven Selenium automation project.
The path of my local eclipse workspace is:
/media/user/Data/Automation_Scripts
and the complete path of the pom.xml file used to execute the project is:
/media/user/Data/Automation_Scripts/[project_name]/pom.xml
Now, I have installed Jenkins and added a Maven project to it. When I try to enter the path my project's pom.xml file in the 'Root POM' text field under 'Build' I get following error:
No such file: ‘/media/user/Data/Automation_Scripts/test/pom.xml’
Whereas if I navigate to the same path the pom.xml file is present. When I build the Maven project in Jenkins, following error is shown:
Started by user Test Building in workspace
/var/lib/jenkins/jobs/TEST/workspace Parsing POMs ERROR: No such file
/media/user/Data/Automation_Scripts/test/pom.xml Perhaps you need to
specify the correct POM file path in the project configuration?
Finished: FAILURE
Update:
I created a pom.xml file in my jenkins workspace which is located at:
/var/lib/jenkins/jobs/TEST/workspace
In this pom file have given path of my actual pom.xml (which is located in another folder) in the following way:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name>
<artifactId>jenkins_test</artifactId>
<parent>
<groupId>ca.test</groupId>
<artifactId>maven_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>/media/user/Data/Automation_Scripts/test/pom.xml</relativePath>
</parent>
</project>
Still I am getting following error now:
Building in workspace /var/lib/jenkins/jobs/TEST/workspace
Parsing POMs
ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact ca.test:maven_test:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 6, column 9
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:364)
at hudson.maven.MavenEmbedder.buildProjects(MavenEmbedder.java:361)
at hudson.maven.MavenEmbedder.readProjects(MavenEmbedder.java:331)
at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1301)
at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1098)
at hudson.FilePath.act(FilePath.java:1018)
at hudson.FilePath.act(FilePath.java:996)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.parsePoms(MavenModuleSetBuild.java:960)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:679)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1720)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:404)
Finished: FAILURE
I guess there is something wrong with the relative path. Can you tell me what I am missing here?
Try providing relative path instead of actual absolute path.
By default jenkins job considers path as workspace path.
Make pom.xml available in workspace of the job and provide path as just file name I.e pom.xml

How to build a feature to a zip file using Tycho

I'm trying to export an Eclipse feature using Tycho, replacing the "Export Wizard" found on the Eclipse overview of the feature. The wizard gives the option for the export destination as a zip file. Is there a way to do the same with Tycho?
In order to build a zip file with the feature and the feature's plug-ins, you need to add a module of the assembly packaging type eclipse-repository to your reactor:
Add an eclipse-repository module with the same parent POM as the
eclipse-feature module (in order to inherit the same target
platform configuration).
Create a category.xml file in the root of the new module with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature id="todo.your.feature.id" />
</site>
Add the new module to your root POM.

How to manage shared resources for several web apps in Maven AND Eclipse?

Note: I didn't get any response in the first version of this question, so I modified it to be more generic...
Context
My project is divided into several maven modules and several web-applications. Here is the structure:
my-project
+ pom.xml
+-- commons
+-- persistence
+-- ...
+-- web-app-1
+-- web-app-2
+-- ...
All the web applications share common resources, such as JS, CSS and images files.
Instead of duplicating these resources in each web-app-X, I decided to create another project called web-resources, which is a WAR project.
The structure is then the following one:
my-project
+ pom.xml
+-- commons
+-- persistence
+-- ...
+-- web-app-1
+-- web-app-2
+-- ...
+-- web-resources
+-- pom.xml
+-- src/main/webapp
+-- web.xml (which is almost empty, just need to be present for Maven)
+-- web_resources
+-- css
+-- images
+-- javascript
Maven
In Maven 2 (or Maven 3, as I just migrated my project to maven 3.0.2), this configuration is easy to manage as all web-app-X declare web-resources as a dependency:
<groupId>foo.bar</groupId>
<artifactId>web-app-1</artifactId>
...
<dependencies>
<dependency>
<groupId>foo.bar</groupId>
<artifactId>web-resources</artifactId>
<version>${preclosing-version}</version>
<type>war</type>
</dependency>
...
So when I build my WAR project, it first get the web-resources.war (built just before), unzip it, and build on top of it the web-app-X web-application.
This way, my WAR file will contains also a directory called web-resources/ that contains the shared resources.
This is the war overlay principle.
So on a Maven point of view, everything is fine!
Eclipse
Now, here comes the main problem: having a good Eclipse configuration.
Question: How can I use my current configuration to be managed correctly by Eclipse? In particular, when I deploy any web-app-X in Tomcat using Eclipse...
Note that I want to get the more automatizable (?) configuration, and avoid any manual steps, as this configuration should be used by dozens of developers...
For me, the best solution seems to use the linked resources of Eclipse. Thus, I set the following configuration in my web-app-X pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
<linkedResources>
<linkedResource>
<name>web_resources</name>
<type>2</type>
<location>${project.basedir}\..\web-resources\src\main\webapp\web_resources</location>
</linkedResource>
</linkedResources>
</configuration>
</plugin>
...
When I run the mvn eclipse:eclipse configuration, it adds succesfully this information in my .project file:
<projectDescription>
...
<linkedResources>
<link>
<name>web_resources</name>
<type>2</type>
<location>C:\dev\project\web-resources\src\main\webapp\web_resources</location>
</link>
</linkedResources>
<projectDescription>
Now, I import my project in Eclipse.
Problem: in Project properties > Java Build Path > Source, I don't see the Link Source present.
I only see my four Maven default directories (src/main/java, src/main/resources, src/test/java and src/test/resources).
What is strange is that when I try to manually add the linked resources, it refuses and says that it already exists...
So when I deploy my web application on my Tomcat in Eclipse, it does not deploy the web_resources directory, and thus I don't get the CSS / JS / images deployed.
After some tests, it seems that I have to do two modifications:
Add the line <classpathentry kind="src" path="web_resources" output="src/main/webapp/web_resources"/> in my .classpath file;
Remove the <project>preclosing-web-resources</project> in the .project file.
Note that using this configuration, Eclipse will copy (and keep synchronization) the content of web_resources project in my web-app-X/src/main/webapp/web_resources, but this is not a problem (this directory is ignored by the SCM).
The only automated solution I found was to create a simple Maven plugin that do the two previous modification, and then run the following command (or use a .bat file):
mvn eclipse:clean eclipse:eclipse myEclipsePlugin:eclipse
Question
Is there a better way to manage such configuration?
Technical information
Java 6, Maven 3.0.2, maven eclipse plugin 2.8, Eclipse 3.3.2 (but I can test with newer version of Eclipse), no m2eclipse plugin.
Starting with Servlet 3.0, you can share resources by putting them within the src/main/resources/META-INF/resources directory.
When the webapp deploys, Servlet 3.0 makes those resources available from the context path. For example, in your case...
web-resources
-- src
---- main
------ resources
-------- META-INF
---------- resources
------------ css
-------------- global.css
------------ images
-------------- background.png
Let's assume that my_project has a dependency on web-resources and is deployed to the url http://my.localhost:8080/myProject.
With that configuration, the following URLs will resolve to the correct resources:
http://my.localhost:8080/myProject/css/global.css
http://my.localhost:8080/myProject/images/background.png
IF you have a name conflict between the resources and your actual application, the application will win.
Be sure your web.xml states you are using Servlet 3.0
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
You might want to take a look at this blog post. It covers a method for sharing resources using maven:
http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/