I am trying to call test classes from src main using maven but unable compile using maven my project structure is like below
My main class looks like
package com.automation.selenium.demo;
import com.automation.selenium.test.demo.TestClass;
public class EntryClass {
public static void main(String[] args) {
System.out.println("!!!!!!!!!!!!!!! Calling From Main Class !!!!!!!!!!!!");
TestClass testNGtest = new TestClass();
testNGtest.testMethod();
}
}
My test class looks like
package com.automation.selenium.test.demo;
public class TestClass {
public void testMethod() {
System.out.println("!!!!!!!!!!!!!!! Calling From Test Class !!!!!!!!!!!!");
}
}
My pom.xml 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>com.ibm.automation.selenium.demo</groupId>
<artifactId>Demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>${project.build.directory}\test-classes\com\automation\selenium\test\demo</argument>
</arguments>
<!-- <testSourceRoot>${project.basedir}/src/test{</testSourceRoot> -->
<mainClass>com.automation.selenium.demo.EntryClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have use the following command to run
clean compiler:testCompile exec:java
but it is showing the following error
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project Demo: Unable to parse configuration of mojo org.codehaus.mojo:exec-maven-plugin:1.6.0:java for parameter arguments: Cannot store value into array: ArrayStoreException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginConfigurationException
I am new in Maven anyone please help me to findout the issue.
A class in src/main/java should never call a class in src/test/java. Classes in src/test/java are meant to test the classes in src/main/java. They are not meant to be used as dependencies or parts of self-constructed test frameworks.
If you want to build a jar for testing, put the classes into src/main/java.
Related
Please guide me how to proceed further while doing the mvn release:prepare in my spring boot project also do tell how to add ssh key to my project if it is required.
I tried many solutions but none work as it is showing the same error everytime and this is my modular approach based project and IDE I am using is IntelliJ.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release- plugin:2.5.3:prepare (default-cli) on project vj-pet-clinic: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] git#github.com: Permission denied (publickey).
[ERROR] fatal: Could not read from remote repository.
[ERROR] Please make sure you have the correct access rights
[ERROR] and the repository exists.
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
my pom.xml file is :-
<?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>
<packaging>pom</packaging>
<modules>
<module>pet-clinic-data</module>
<module>pet-clinic-web</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.vinamra</groupId>
<artifactId>vj-pet-clinic</artifactId>
<version>0.0.1</version>
<name>vj-pet-clinic</name>
<description>VJ pet clinic project</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<goals>install</goals>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
</plugins>
</build>
<scm>
<developerConnection>scm:git:git#github.com:username/repository.git</developerConnection>
<tag>vj-pet-clinic-0.0.1</tag>
Please help me how to push the release the plugin using maven.
You can use HTTPS instead of SSH to avoid the keys exchange. Here is an example:
<scm>
<url>https://github.com/(username)/(repo)</url>
<connection>scm:git:https://github.com/(username)/(repo).git</connection>
</scm>
Replace (username) and (repo) accordingly.
I am new to Maven and I am trying to write a small piece of Java code. I am including some packages. Maven seems to download everything I am expected to need but when it comes to compiling it fails saying it can't find a particular class. The errors further state that it can't find any of of my imports. Can someone tell me what I am missing?
This is my code:
package in.myscratchpad.app;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodb.AmazonDynamoDBClient;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
AmazonDynamoDBClientBuilder builder = AmazonDBClientBuilder.standard();
}
}
This is my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>in.myscratchpad.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>in.myscratchpad.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<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>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.60</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</project>
These are the errors I get:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-app: Compilation failure: Compilation failure:
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[3,21] package com.amazonaws does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[4,21] package com.amazonaws does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[5,26] package com.amazonaws.auth does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[6,34] package com.amazonaws.auth.profile does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[7,29] package com.amazonaws.regions does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[8,29] package com.amazonaws.regions does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[9,39] package com.amazonaws.services.dynamodb does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[20,9] cannot find symbol
[ERROR] symbol: class AmazonDynamoDBClientBuilder
[ERROR] location: class in.myscratchpad.app.App
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[20,47] cannot find symbol
[ERROR] symbol: variable AmazonDBClientBuilder
[ERROR] location: class in.myscratchpad.app.App
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
When I simple keep the Hello, World code without the AWS packages it works fine, when I try to build the service client I get these errors.
It says
...cannot find symbol
[ERROR] symbol: variable AmazonDBClientBuilder
[ERROR] location: class in.myscratchpad.app.App
Which seams to explain clearly that it can compile in.myscratchpad.app.App because there is a symbol in it (namely AmazonDBClientBuilder) which can not be found!
I don't know what this class is for but given that
you do not have import for AmazonDBClientBuilder class
you assign the result to AmazonDynamoDBClientBuilder type
isn't that a typo in your code and you should use AmazonDynamoDBClientBuilder.standard() instead?
I am having a Maven project that has following file structure :
src/main/java/com/TestFolder/{Java file name}
This Java file contains a main method that I need to execute with argument from command line. How this can be done ? Please help.
Currently am doing something like this :
mvn exec:java -Dexec.mainClass=src.main.java.com.TestFolder.MyMainJavaClass -Dexec.args="1"
Is this right syntax to do it ? Because when i run this i get following error :
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven- plugin:1.4.0:java (default-cli) on project Staples_7Lakh: Execution default-cli of goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java failed: Plugin org.codehaus.mojo:exec-maven-plugin:1.4.0 or one of its dependencies could not be resolved: The following artifacts could not be resolved: backport-util-concurrent:backport-util-concurrent:jar:3.1, org.apache.maven:maven-core:jar:2.2.1, org.codehaus.plexus:plexus-utils:jar:3.0.20: Could not transfer artifact backport-util-concurrent:backport-util-concurrent:jar:3.1 from/to central (https://repo.maven.apache.org/maven2): GET request of: backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar from central failed: SSL peer shut down incorrectly -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
This problem is because the dependancies are missing in the executable jar. The executable jar needs all run time dependencies to be present. I also had a similar problem which I solved using maven assembly plugin please find below configuration with the pom file for the assembly plugin configuration -
<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>xyz.jeetendra.hibernate.Sample</groupId>
<artifactId>Excercise1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Excercise1</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>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<build>
<finalName>UserService</finalName>
<plugins>
<!-- maven Assenmbly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<!--get all project dependency -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- Main class in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>xyz.jeetendra.hibernate.sample.Service</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
BR
I started an Android project, and by default it is built with ANT, I am trying to upgrade it to Maven so I can get rid of compile time problems I am having with Android SDK, and ease of library import and management. The problems I have encountered are :
1) How to modify build.xml to instruct it to use maven.
2) Maven complaining folder structure is wrong.
Here is my build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project name="myapp" default="help">
<property file="local.properties"/>
<property file="ant.properties"/>
<property environment="env"/>
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME"/>
</condition>
// and more
So I presume I have to modify the ant.properties attribute, how can I suggest to use Maven??
Here is the POM.xml I have pasted in the Parent directory of the project, but when I try to run mvn compile, I get the following error :
Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:4.0.0-rc.2:generate-sources (default-generate-sources) on project gs-maven-android:
[ERROR]
[ERROR] Found files or folders in non-standard locations in the project!
[ERROR] ....This might be a side-effect of a migration to Android Maven Plugin 4+.
[ERROR] ....Please observe the warnings for specific files and folders above.
[ERROR] ....Ideally you should restructure your project.
[ERROR] ....Alternatively add explicit configuration overrides for files or folders.
[ERROR] ....Finally you could set failOnNonStandardStructure to false, potentially resulting in other failures.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
And finally, here is the POM.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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hello</groupId>
<artifactId>MyAPP</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.0.0-rc.2</version>
<configuration>
<sdk>
<platform>20</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
So what am I doing wrong here? Any help would be nice. I am using Intellij Idea on Ubuntu Linux. Thanks.
Please update to a full release version and then update the error message in the post. The latest release is 4.3.0.
The warning is about the source code and other sources being located in non-standard folders. You should use the standard structure. The full version will show error message with details where everything should be.
I've worked my way through the example hello world dropwizard project which appears error free in IntelliJ (I'm an Eclipse veteran but new to IntelliJ) but compilation fails via maven.
The source directory contains:
/src/main/java/com/example/helloworld/HelloWorldConfiguration.java
/src/main/java/com/example/helloworld/HelloWorldService.java
where HelloWorldService looks like:
package com.example.helloworld;
import com.example.helloworld.resources.HelloWorldResource;
import com.example.helloworld.health.TemplateHealthCheck;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
public class HelloWorldService extends Service<HelloWorldConfiguration> {
public static void main(String[] args) throws Exception {
new HelloWorldService().run(args);
}
#Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
bootstrap.setName("hello-world");
}
#Override
public void run(HelloWorldConfiguration configuration,
Environment environment) {
final String template = configuration.getTemplate();
final String defaultName = configuration.getDefaultName();
environment.addResource(new HelloWorldResource(template, defaultName));
environment.addHealthCheck(new TemplateHealthCheck(template));
}
}
and maven is coming back with:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-project: Compilation failure: Compilation failure:
[ERROR] /Users/markdsievers/IdeaProjects/dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java:[9,48] cannot find symbol
[ERROR] symbol: class HelloWorldConfiguration
[ERROR] /Users/markdsievers/IdeaProjects/dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java:[15,38] cannot find symbol
[ERROR] symbol : class HelloWorldConfiguration
[ERROR] location: class com.example.helloworld.HelloWorldService
[ERROR] /Users/markdsievers/IdeaProjects/dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java:[20,21] cannot find symbol
[ERROR] symbol : class HelloWorldConfiguration
[ERROR] location: class com.example.helloworld.HelloWorldService
where the pom.xml looks like:
<?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>com.example.helloworld</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
</dependencies>
<properties>
<!-- use UTF-8 for everything -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
I get the same error from maven if the compile goal is run from the command line or within IntelliJ. Source root (/src/main/java) is set in IntelliJ and no amount of cleaning and recompiling has had any effect.
Any suggestions appreciated.
Found the issue... HelloWorldConfiguration did not have a .java extension. Pretty evil IMO, IDE is treating it as a valid java file and was created via the New Java Class (or must not have or something went wrong). Anyways, probably need to enable view of file extensions.