I am using maven project for UI automation and I need to run some tests in multiple environment and multiple browsers.
I have created added the pom.xml file and declared the properties in it. But when i execute it through the terminal i get errors.
command i used-
mvn clean
mvn test -Denvironment=test -Dbrowser=chrome
My Xml file-
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>org.example</groupId>
<artifactId>ui-automation-projects</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<property>
<environment>${environment}</environment>
</property>
<property>
<browser>${browser}</browser>>
</property>
</properties>
<dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
Error-
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-parseable POM D:\work\Cucumber_Projects\ui-automation-projects\pom.xml: TEXT must be immediately followed by END_TAG and not START_TAG (position: START_TAG seen ...\n ... #13:26) # line
13, column 26
You must delete <property> and add your property under <properties>.
<properties>
<environment>${environment}</environment>
<browser>${browser}</browser>
</properties>
Also, you have an extra '>' after </browser>
Project properties in pom.xml are declared like this:
<properties>
<environment>default-environemnt-value</environment>
<browser>default-browser-value</browser>>
</properties>
You can read more in POM reference
You have error during the parson pom.xml file I checked it into my Idea and corrected. You didn't have </project> tag and <dependencies> </dependencies> were redundant. Also there should be answer
<properties>
<environment>${envValue}</environment>
<browser>${browserValue}</browser>
</properties>
After this the file builds correctly.
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>org.example</groupId>
<artifactId>ui-automation-projects</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<environment>${envValue}</environment>
<browser>${browserValue}</browser>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
</project>
I have seen u r POM couple of ties and have seen my local pom how I have defined my dependencies and POM
I found 2 things
You have defined the properties already in which u can directly add the value
(Here in your case it is environment and Browser)
else define alone as follows in properties
${environment}
I haven't seen end for the Project in the POM.
Try adding that and that should work.
enter image description here
Related
This is the first time I have tried to make a minecraft plugin, and I get this error:
I am not a programmer, so can some one say why I had this error when I go in build.xml?
Eclipse version : 4.20.0
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>test.plugin.test</groupId>
<artifactId>test</artifactId>
<version>1.0-Complete</version>
<packaging>jar</packaging>
<name>main test</name>
<description>test</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</project>
The error message suggests that the software reading the file is expecting Ant stuff but found something else, which it could not interpret. Indeed build.xml is a typical name for a build file used by Ant, but the contents shown appear to be meant to be saved as a pom.xml file to be used by Maven. A good first step might be to correct the filename; perhaps then the program would read it in the right frame of mind.
I am trying to migrate my application from Java 8 to Java 11. In of one of my project classes, I have the line Security.addProvider(new com.sun.crypto.provider.SunJCE());. I am getting a compile error for this line. How to resolve this?
You can't access com.sun packages without explicitly setting them on your compile options. After adding --add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED to compilerArgs it compiles without any error.
Code:
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Maven:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArgs>
<arg>--add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
java.security.Security.getProviders() returns you all the providers including the SunJCE.
Stream.of(java.security.Security.getProviders()).forEach(System.out::println);
So better option to get the SunJCE instane is java.security.Security.getProvider("SunJCE")
I am trying to test the basic structure of my GUI application that I started using WindowBuilder. I am also using Maven so that I can just download the dependencies from their repository.
I don't have any errors when I do a "Maven Clean" or a "Maven Install", but when I try to do "Run As--->Java Application", I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-win32-3044 in java.library.path
swt-win32-3044 was what I found in the Maven Repository to satisfy the requirements for the WindowBuilder. I don't have any errors in my POM file, but here is what I have...
<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>
<groupId>blah.blah.blah</groupId>
<artifactId>blah</artifactId>
<version>1.0.0</version>
<name>blah</name>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-win32</artifactId>
<version>3.0m8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>java.library.path</name>
<value>${project.build.directory}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Any help would be greatly appreciated. Thanks.
So I changed the POM around a little bit. I tried a different Maven dependency for WindowBuilder and changed my syntax for defining the maven-surefire-plugin.
<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>
<groupId>blah.blah.blah</groupId>
<artifactId>blah</artifactId>
<version>1.0.0</version>
<name>blah</name>
<dependencies>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
It now launches the Java application window as expected.
I am using maven in my project & I've put database.properties file under
maven resources folder.
I am accessing it in spring application context
<context:property-placeholder location="classpath:database.properties" />
But I don't understand why I am getting this file not found error on server start.
Could not load properties; nested exception is
java.io.FileNotFoundException: class path resource
[database.properties] cannot be opened because it does not exist
To my knowledge whatever resource is put under resources folder it is added to the classpath automatically by maven.
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>myapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>myapp</finalName>
</build>
</project>
NOTE: Seems like there is some problem with the M2E plugin of eclipse luna. Executed the same code in Juno & it worked fine.
That's not enough to build a deployable war file with maven. You need at least the war plugin. There's a thorough tutorial here:
http://crunchify.com/how-to-create-a-war-file-from-eclipse-using-maven-plugin-apache-maven-war-plugin-usage/
Your pom will look something like below, and you'll need to run mvn clean install against that.
Also I see you have a spring app, where are the spring dependencies in the pom file?
<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>
<groupId>CrunchifyTutorial</groupId>
<artifactId>CrunchifyTutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>
I've created a simple project in Java Maven. I can run this project by:
1:
java -cp target/MavenTestApp-1.0-SNAPSHOT.jar org.koushik.javabrains.App
But I would like to run it by:
2:
java -jar target/MavenTestApp-1.0-SNAPSHOT.jar
To run it by second method I need to change manifest file. I am using maven so I think that in this case I need to change the pom.xml file. My pom.xml file is:
<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>
<groupId>org.koushik.javabrains</groupId>
<artifactId>MavenTestApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenTestApp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I need to add something like this:
<mainClass>org.koushik.javabrains.App</mainClass>
But I not pretty sure where and how to do that? Could you also tell me if this line is good:
2:
java -jar target/MavenTestApp-1.0-SNAPSHOT.jar
Maybe at the end of this line there should be something or it is sufficient? Thanks.
Take a look at the Maven jar plugin documentation.
You will need to configure something similar in your .pom:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.koushik.javabrains.App</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>