Im trying learn Spring and Maven but im having some trouble.
When I go to run my tests from the terminal using mvn clean install I'm getting this error: java.lang.IllegalArgumentException: URI is not hierarchical . This is the block of code that throws the error :
LocationWeatherRootResponseTest.class.getClassLoader().getResource("extent.xml")).toURI()
When I change the above code to the following Im getting a null pointer exception.
LocationWeatherRootResponseTest.class.getClassLoader().getResourceAsStream("extent.xml")))
Update
When I change the code to the below Im getting a new error.
File file = new File(WeatherTest.class.getClassLoader().getResource("extent.xml").getPath());
Reporter.loadXMLConfig(file);
stacktrace :
java.io.FileNotFoundException: file:/home/user/IdeaProjects/spring-cucumber-test-harness/common/target/common-1.0-SNAPSHOT.jar!/extent.xml (No such file or directory)
I managed to solve this issue using maven-remote-resources-plugin . Now when I run mvn clean install on the master POM the framework runs from e2e.
In the module containing the resources I wanted to share, I added the following to the POM file
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.xml</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
In the module where I want to use the resource. I added the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<configuration>
<resourceBundles>
<resourceBundle>{groupId}:{resource artifactId}:1.0-SNAPSHOT</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
Related
I'm using Intellij's ui-designer in my Maven project and I understand from this question that I need to use ideauidesigner-maven-plugin to create a jar out of my code.
So I add this to my pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
And now when I'm trying to create the jar with "mvn clean package",
I'm getting the following error "Index 20838 out of bounds for length 6699".
here is the error with the call stack:
I have a pom file that correctly generates the grpc and protobuf source files I need in target/generated-sources when run from the command line. But when I build in vscode those directories are empty and references to the protobufs are undefined. Here's the section of my pom file that builds the grpc source.
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
I added the following based on what I read in other posts to prevent vscode/eclipse from removing the generated source directories
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/protobuf/grpc-java</source>
<source>/target/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
When vs-code builds, the target generated-source directories are there, but there is no source in them. We had a similar problem with intellij but were able to work around it by running the maven command line build before opening intellij but that does not seem to work for vscode.
Use protoc-jar-maven-plugin instead.
Sample usage please view protoc-jar-maven-plugin.
https://devcenter.heroku.com/articles/run-non-web-java-processes-on-heroku
I followed the above tutorial to deploy my app on heroku. When i package the code in my IDE (intelliJ IDEA) everything works fine. A target folder is created that has a sub floder named bin and it contains two files : worker and worker.bat
From my root director, if i run the command sh target/bin/worker then the application executes properly and desired.
On the otherhand after i push the code to heroku and use the command :
heroku ps:scale worker=1
I get this error :-
sh: 0: Can't open target/bin/worker
Process exited with status 127
State changed from up to crashed
My POM.xml is exactly same as it is in the tutorial with just few extra dependencies.
What is the issue and how can it be resloved ?
POM.xml :-
<dependencies>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>MainClass</mainClass>
<name>worker</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
I am using the maven-pmd-plugin in my project. When I build the project, I am getting duplicate (due to java constructor code) code error during cpd-check. How do I exclude specific java files from CPD check?
Add an excludeFromFailure file in cpd-check goal configuration in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.6</version>
<executions>
<execution>
<goals>
<goal>cpd-check</goal>
</goals>
<configuration>
<excludeFromFailureFile>exclude-cpd.properties</excludeFromFailureFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The exclude-cpd.properties file must contain the full class name.
https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.6/examples/violation-exclusions.html
I have created an automation framework where I am reading values from a property file say "config.properties".
My config.propertioes file contains following :
BrowserName=${browser}
Environment=${env}
I am reading browser value from the property file and passing it to my selenium script to run it.
Now I wants to replace "${browser}" && "${env}" with value "ie" && "IT" using pom.xml. Is there any way/plugin using which I can edit a property file using pom.xml.
Please suggest.
#Keshava
I am putting whole example below as suggested below :
1.Have 2 property files: ◦project.properties: This is the file that we commit in the repository. It consists data as follows: ◾project.connection.username=##DB_USERNAME##
project.connection.password=##DB_PASSWORD##
◦build.properties: This is the file that we do not commit in the repository and is maintained at each of the deployment environments, be it the developers env., UAT env or Production env. The contents of this file are as follows: ◾db.username=mydbuser
db.password=mydbpassword
2.In the project’s pom.xml add the following plugin and a execution:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>1.3.5</version>
<executions>
<execution>
<id>replaceTokens</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>target/classes/project.properties</file>
<replacements>
<replacement>
<token>##DB_USERNAME##</token>
<value>${db.username}</value>
</replacement>
<replacement>
<token>##DB_PASSWORD##</token>
<value>${db.password}</value>
</replacement>
</replacements>
</configuration>
</plugin>
from above, I understand that "##DB_USERNAME##" is from "project.properties". But, from which properties file this "${db.username}" value will be taken?. how my pom will understand from where to take "${db.username}" .
Do I need to pass this value in maven goal like below :
mvn clean install -Ddb.username=myuserid
Hello you can use the maven resource plugin.
This plugin implement "Maven Filtering".
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>selenium-profile-chrome</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/selenium</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
you could tryin using the maven replacer plugin
See https://code.google.com/archive/p/maven-replacer-plugin/
See an example here