I'm trying to build my project and I keep getting an error, saying the package doesn't exist why the IDE says it's fine (no compile error). Obviously, something is not consistent between my pom.xml and the way the IDE compiles.
Here how my project structure looks like:
Here is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.oo</groupId>
<artifactId>employeeservice</artifactId> <!-- Docker complains if the name contains upper case -->
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>EmployeeService</name>
<description>This service takes care of all the employee related operations</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
If I remove Employee (entity) and EmployeeRepository and just have the controller with a dummy "Hello World", it works fine! I tried to put them under the same package, same issue!
Employee class
package com.oo.employeeservice.dao.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
public class Employee {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String firtName;
private String lastName;
private String email;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirtName() {
return firtName;
}
public void setFirtName(String firtName) {
this.firtName = firtName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Using default Spring boot configuration:
package com.oo.employeeservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
Controller
package com.oo.employeeservice.controller;
import com.oo.employeeservice.dao.EmployeeRepository;
import com.oo.employeeservice.dao.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
#RestController
#RequestMapping("/api")
public class EmployeeController {
#Autowired
private EmployeeRepository repo;
#RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Iterable<Employee>> all() {
return new ResponseEntity<Iterable<Employee>>(repo.findAll(), HttpStatus.OK);
}
#RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> create(#RequestBody Employee employee) {
repo.save(employee);
return new ResponseEntity<String>(HttpStatus.CREATED);
}
}
Maven log:
~/IdeaProjects/EmployeeService$ mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EmployeeService 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) # employeeservice ---
[INFO] Deleting /home/mahdi/IdeaProjects/EmployeeService/target
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) # employeeservice ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) # employeeservice ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /home/mahdi/IdeaProjects/EmployeeService/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/dao/EmployeeRepository.java:[3,41] package com.oo.employeeservice.dao.entity does not exist
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/dao/EmployeeRepository.java:[9,60] cannot find symbol
symbol: class Employee
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[4,41] package com.oo.employeeservice.dao.entity does not exist
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[18,36] cannot find symbol
symbol: class Employee
location: class com.oo.employeeservice.controller.EmployeeController
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[23,50] cannot find symbol
symbol: class Employee
location: class com.oo.employeeservice.controller.EmployeeController
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[19,44] cannot find symbol
symbol: class Employee
location: class com.oo.employeeservice.controller.EmployeeController
[INFO] 6 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.872 s
[INFO] Finished at: 2018-07-15T15:59:38+08:00
[INFO] Final Memory: 31M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project employeeservice: Compilation failure: Compilation failure:
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/dao/EmployeeRepository.java:[3,41] package com.oo.employeeservice.dao.entity does not exist
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/dao/EmployeeRepository.java:[9,60] cannot find symbol
[ERROR] symbol: class Employee
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[4,41] package com.oo.employeeservice.dao.entity does not exist
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[18,36] cannot find symbol
[ERROR] symbol: class Employee
[ERROR] location: class com.oo.employeeservice.controller.EmployeeController
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[23,50] cannot find symbol
[ERROR] symbol: class Employee
[ERROR] location: class com.oo.employeeservice.controller.EmployeeController
[ERROR] /home/mahdi/IdeaProjects/EmployeeService/src/main/java/com/oo/employeeservice/controller/EmployeeController.java:[19,44] cannot find symbol
[ERROR] symbol: class Employee
[ERROR] location: class com.oo.employeeservice.controller.EmployeeController
[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
I found the silliest problem with Intellij. If you look for Employee class in the package explorer in the image attached, you can see the file is marked as a class. When I opened the file location in the terminal, I realized it doesn't have ".java" extension. Obviously, maven won't recognize the file as a java file!
I have faced the same issue once. The problem was I have created the folder structure with name test.demo.exmple.java and it got created in the same way in explorer ( this can be seen if you open same files on explorer) means folder name was test.demo where the system is looking for test/demo/example.java.
So in your case I think path would be com.oo.employeeservice instead of com/oo/employeeservice
Related
I get this error package org.junit doesn't exists in vscode when I import
import junit.framework.Test; or import static org.junit.Assert.assertEquals;
this is my test file
package com.wezigo.myapp.service;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MyServiceTest {
#Test
public void testCompute(){
MyService service =new MyService();
//MyService service = new MyService();
double a = 15;
double b = 15;
double expected = 20;
double result = service.compute(a,b);
assertEquals(expected, result,0.001 );
}
}
this is pom.xml file content
<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.wezigo</groupId>
<artifactId>myapp</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>
</project>
i try the solution in this address
**Why does vscode not recognize the import org.junit?
** but i use vscode 1.60.0 and this command is not availlable View -> Command Palette -> Java: Clean Java Language Server Workspace
when compile, i get thes error
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.083 s
[INFO] Finished at: 2021-09-24T12:10:31+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/rodolphe/javaTraining/work1). Please verify you invoked Maven from the correct directory. -> [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/MissingProjectException
Try
package com.wezigo.myapp.service;
public class MyServiceTest {
public void testCompute(){
MyService service =new MyService();
double a = 15;
double b = 15;
double expected = 20;
double result = service.compute(a,b);
assert Math.abs(expected - result) <= 0.001;
}
}
A popular fallacy is that you need junit for unit testing.
I am new to coding. I am getting below error when trying to run java application in springboot with H2db.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 8.777 s <<< FAILURE! - in com.example.demo.DemoApplicationTests
[ERROR] contextLoads(com.example.demo.DemoApplicationTests) Time elapsed: 0.002 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] DemoApplicationTests.contextLoads ยป IllegalState Failed to load ApplicationCon...
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.028 s
[INFO] Finished at: 2019-05-26T22:46:54+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project demo: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\v\Desktop\demo\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[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
Here is my 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Application :
package com.example.demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.example.demo.StudentRepository;
#SpringBootApplication
#EntityScan("com.example.demo.Student")
#EnableJpaRepositories("com.example.demo.StudentRepository")
public class H2demoApplication implements CommandLineRunner {
// mvn spring-boot:run
private Logger LOG = LoggerFactory.getLogger("H2demoApplication");
StudentRepository studentRepository;
#Autowired
public H2demoApplication(StudentRepository studentRepository) {
this.studentRepository = studentRepository;
}
public static void main(String[] args) {
SpringApplication.run(H2demoApplication.class, args);
}
#Override
public void run(String... args) throws Exception {
LOG.info("Student count in DB: {}", studentRepository.count());
}
}
Entity:
package com.example.demo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
#Entity
public class Student {
#Id
#GeneratedValue
private Long ID;
private String NAME;
private String SECTION;
public Student() {
}
public Student(Long ID, String NAME, String SECTION) {
this.ID = ID;
this.NAME = NAME;
this.SECTION = SECTION;
}
public Long getId() {
return ID;
}
public void setId(Long ID) {
this.ID = ID;
}
public String getName() {
return NAME;
}
public void setName(String NAME) {
this.NAME = NAME;
}
public String getSection() {
return SECTION;
}
public void setSection(String SECTION) {
this.SECTION = SECTION;
}
}
Repository:
package com.example.demo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.demo.Student;
#Repository
public interface StudentRepository extends JpaRepository<Student, Long> {
}
O/p should have "Student count in DB: 2"
my java version is :
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
Getting above error when running mvn clean install in command line.
I defined h2db configurations in application.properties file as below
H2 configurarion
spring.h2.console.enabled=true
spring.h2.console.path=/h2
Datasource
spring.datasource.url=jdbc:h2:~/test
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
in data.sql file kept data to be inserted :
insert into STUDENT
values(10001,'Ajay', 'AAA1');
insert into STUDENT
values(10002,'Ajit', 'AAA2');
You need to provide the hibernate dialect to configure hibernate befor connecting
use
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
The error looks like, it can't figure out the dialect to be used with H2.
The dialect specifies the type of database used in hibernate so that hibernate generate appropriate type of SQL statements.
The dialect to be used for h2 is this:
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Also being new to programming might confuse you to write optimal code. It looks like, you are mixing up things from older versions of spring boot and spring. Please use,
https://start.spring.io
to generate your initial spring boot project with the required dependencies. You can follow the below tutorial which explains nicely to get started with spring boot and h2.
https://www.springboottutorial.com/spring-boot-and-h2-in-memory-database
I am trying to use maven to run my unit tests in terminal.
When I run mvn clean test or mvn test I get the following output:
user#user:~/Documents/git/projectname$ mvn test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project name 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # projectname ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # projectname ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # projectname ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # projectname ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # projectname ---
[INFO] Surefire report directory: /home/user/Documents/git/QA-projectname/target/surefire-reports
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom
[INFO] Failure detected.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.258 s
[INFO] Finished at: 2018-06-13T15:36:31-06:00
[INFO] Final Memory: 13M/54M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project projectname: Unable to generate classpath: org.apache.maven.artifact.resolver.ArtifactResolutionException: Unable to get dependency information for org.apache.maven.surefire:surefire-junit4:jar:2.12.4: Failed to retrieve POM for org.apache.maven.surefire:surefire-junit4:jar:2.12.4: Could not transfer artifact org.apache.maven.surefire:surefire-junit4:pom:2.12.4 from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
[ERROR] org.apache.maven.surefire:surefire-junit4:jar:2.12.4
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)
[ERROR] Path to dependency:
[ERROR] 1) dummy:dummy:jar:1.0
[ERROR]
[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/MojoExecutionException
I have also tried to run a single test with mvn test -Dtest=testname but I get the same error.
Here is my pom.xml 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>groupidhere</groupId>
<artifactId>artifactidhere</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>2.21.0</version>
<type>pom</type>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>Small Store Regression</name>
<description>description here</description>
</project>
Here is an example of one of my tests:
package loginPurchase;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import PageObjects.CartScreen;
import PageObjects.HomeScreen;
import testBase.TestBase;
import java.math.BigDecimal;
import static org.junit.Assert.assertTrue;
public class ProductTaxPurchases extends TestBase {
#Before
public void setUp() throws Exception {
mobileSetup();
}
#AfterClass
public static void tearDown() throws Exception {
mdriver.quit();
mdriver = null;
}
//The purpose of this test is to add a taxed product to a cart and verify the taxes are correct | and purchase by CC
#Test
public void purchaseTaxedProductByCredit() throws InterruptedException {
HomeScreen hs = new HomeScreen(mdriver);
CartScreen cs = new CartScreen(mdriver);
hs.clickMenu("TestMenuB")
.clickMenuItem("ChrisTaxProduct");
String subTotal = cs.getSubTotal();
String taxAmount = cs.getTax();
String grandTotal = cs.getGrandTotal();
BigDecimal currentSubTotal = new BigDecimal(subTotal);
BigDecimal currentTaxTotal = new BigDecimal(taxAmount);
BigDecimal currentGrandTotal = new BigDecimal(grandTotal);
BigDecimal expectedGrandTotal = currentSubTotal.add(currentTaxTotal);
assertTrue(currentGrandTotal.compareTo(expectedGrandTotal) == 0);
cs.clickPayByCreditCard()
.swipeApprovedCard()
.clickNoReceipt();
}
Second Edit:
Here is the output of mvn dependency::tree
[ERROR] No plugin found for prefix 'dependency' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/chris/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [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/NoPluginFoundForPrefixException
Third edit:
I can successfully run mvn clean test on my windows 10 machine and it works as expected. This problem exists on my Ubuntu 18.04 machine.
Any ideas of what I can do to fix this? I normally run my tests in intellij idea and they run just fine. But I am needing to get these tests ready for upload in Microsoft App Center.
The problem exists with Ubuntu 18.04.
I ran sudo rm /etc/ssl/certs/java/cacerts and then sudo update-ca-certificates -f and this fixed my issue in kubuntu 18.04.
I'm trying to build a new Ambari view (Ambari is an open source project by Apache) that will allow users to manage their OneFS cluster at the same time they're managing Hadoop. I'm pretty new to Maven so I'm hoping this problem is trivially easy to fix (it seems like it would be but so far I haven't been able to figure it out).
I have the following imports defined in a .java file:
package org.apache.ambari.view;
import java.lang.Integer; // Provides several methods for converting an int to a String and a String to an int.
import java.io.IOException; // Signals that an I/O exception of some sort has occurred.
import java.net.UnknownHostException; // Thrown to indicate that the IP address of a host could not be determined.
import java.net.URL; // Uniform Resource Locator - a pointer to a "resource" on the World Wide Web.
import java.net.Socket; // An endpoint for communication between two machines.
import java.util.ArrayList; // Resizable-array implementation of the List interface.
import org.apache.commons.codec.binary.Base64; // Provides Base64 encoding and decoding as defined by RFC 2045.
import org.apache.http.HttpEntity; // An entity that can be sent or received with an HTTP message.
import org.apache.http.util.EntityUtils; // Static helpers for dealing with HttpEntitys.
import org.apache.http.message.BasicNameValuePair; // NameValuePair dictionary type.
import org.apache.http.impl.client.CloseableHttpClient; // Base implementation of HttpClient that also implements Closeable.
import org.apache.http.impl.client.HttpClients; // Factory methods for CloseableHttpClient instances.
import org.apache.http.client.methods.CloseableHttpResponse;// Extended version of the HttpResponse interface that also extends Closeable.
import org.apache.http.client.entity.UrlEncodedFormEntity; // An entity composed of a list of url-encoded pairs for sending HTTP POST requests.
import org.apache.http.client.methods.HttpPost; // An HTTP POST class as defined by section 9.5 of RFC2616
public class Papi {
private String m_clustername;
private String m_username;
private String m_password;
private String m_url;
private String m_sessionurl;
private String m_ipaddress;
private int m_timeout;
private int m_responsecode;
public Papi(String clustername, String username, String password, int port) {
Socket socket;
try {
socket = new Socket(clustername, port);
m_ipaddress = socket.getInetAddress().getHostAddress();
socket.close();
} catch(UnknownHostException e) {
System.out.println("ERROR 1: Failed to open session (UnknownHostException)");
} catch(IOException e) {
System.out.println("ERROR 1: Failed to open session (IOException)");
}
m_url = "https://" + m_ipaddress + ":" + Integer.toString(port);
m_sessionurl = m_url + "/platform" + "/1?describe&list&all";
m_username = username;
m_password = password;
m_responsecode = 0;
}
public int GetResponseCode() {
return m_responsecode;
}
public String GetSessionURL() {
return m_sessionurl;
}
// Makes an https POST request to OneFS.
public String DoPost() throws Exception {
String response;
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(m_sessionurl);
ArrayList <BasicNameValuePair> basicNameValuePair = new ArrayList <BasicNameValuePair>();
basicNameValuePair.add(new BasicNameValuePair("username", m_username));
basicNameValuePair.add(new BasicNameValuePair("password", m_password));
httpPost.setEntity(new UrlEncodedFormEntity(basicNameValuePair));
CloseableHttpResponse reply = httpclient.execute(httpPost);
try {
System.out.println(reply.getStatusLine());
HttpEntity entity = reply.getEntity();
// Parse response body and return as a string.
response = EntityUtils.toString(entity);
System.out.println(response);
// Dispose entity contents.
EntityUtils.consume(entity);
return response;
} finally {
reply.close();
return null;
}
return null;
}
}
However, when I try to build the program using mvn clean package I get the following errors:
root#Martell-AMBARI:/home/tmunson/ambari/ambari-views/examples/onefs-view# mvn clean package
Picked up _JAVA_OPTIONS: -Xmx2048m -XX:MaxPermSize=512m -Djava.awt.headless=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Isilon OneFS View 2.1.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # onefs-view ---
[INFO] Deleting /home/tmunson/ambari/ambari-views/examples/onefs-view/target
[INFO] Deleting /home/tmunson/ambari/ambari-views/examples/onefs-view (includes = [**/*.pyc], excludes = [])
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:regex-property (parse-package-version) # onefs-view ---
[INFO] No match to regex '^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)((\.|-).*)?' found in '2.1.3'. The initial value '2.1.3' is left as-is...
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:regex-property (parse-package-release) # onefs-view ---
[INFO] No match to regex '^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)((\.|-)(([0-9]+)|(SNAPSHOT)|(techwin)).*)?' found in '2.1.3'. The initial value '2.1.3' is left as-is...
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # onefs-view ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) # onefs-view ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/tmunson/ambari/ambari-views/examples/onefs-view/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[28,39] package org.apache.commons.codec.binary does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[30,28] package org.apache.http.util does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[31,31] package org.apache.http.message does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[32,35] package org.apache.http.impl.client does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[33,38] package org.apache.http.client.methods does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[34,35] package org.apache.http.impl.client does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[35,23] package org.apache.http does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[37,37] package org.apache.http.client.entity does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[38,38] package org.apache.http.client.methods does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[39,35] package org.apache.http.impl.client does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[41,1] package org.json does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[86,17] cannot find symbol
symbol: class CloseableHttpClient
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[86,50] cannot find symbol
symbol: variable HttpClients
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[87,17] cannot find symbol
symbol: class HttpPost
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[87,41] cannot find symbol
symbol: class HttpPost
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[89,28] cannot find symbol
symbol: class BasicNameValuePair
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[89,84] cannot find symbol
symbol: class BasicNameValuePair
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[90,44] cannot find symbol
symbol: class BasicNameValuePair
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[91,44] cannot find symbol
symbol: class BasicNameValuePair
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[93,40] cannot find symbol
symbol: class UrlEncodedFormEntity
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[94,17] cannot find symbol
symbol: class CloseableHttpResponse
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[98,21] cannot find symbol
symbol: class HttpEntity
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[101,32] cannot find symbol
symbol: variable EntityUtils
location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[104,21] cannot find symbol
symbol: variable EntityUtils
location: class org.apache.ambari.view.Papi
[INFO] 24 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.002s
[INFO] Finished at: Mon Nov 09 01:06:46 PST 2015
[INFO] Final Memory: 14M/240M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project onefs-view: Compilation failure: Compilation failure:
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[28,39] package org.apache.commons.codec.binary does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[30,28] package org.apache.http.util does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[31,31] package org.apache.http.message does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[32,35] package org.apache.http.impl.client does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[33,38] package org.apache.http.client.methods does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[34,35] package org.apache.http.impl.client does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[35,23] package org.apache.http does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[37,37] package org.apache.http.client.entity does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[38,38] package org.apache.http.client.methods does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[39,35] package org.apache.http.impl.client does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[41,1] package org.json does not exist
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[86,17] cannot find symbol
[ERROR] symbol: class CloseableHttpClient
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[86,50] cannot find symbol
[ERROR] symbol: variable HttpClients
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[87,17] cannot find symbol
[ERROR] symbol: class HttpPost
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[87,41] cannot find symbol
[ERROR] symbol: class HttpPost
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[89,28] cannot find symbol
[ERROR] symbol: class BasicNameValuePair
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[89,84] cannot find symbol
[ERROR] symbol: class BasicNameValuePair
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[90,44] cannot find symbol
[ERROR] symbol: class BasicNameValuePair
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[91,44] cannot find symbol
[ERROR] symbol: class BasicNameValuePair
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[93,40] cannot find symbol
[ERROR] symbol: class UrlEncodedFormEntity
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[94,17] cannot find symbol
[ERROR] symbol: class CloseableHttpResponse
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[98,21] cannot find symbol
[ERROR] symbol: class HttpEntity
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[101,32] cannot find symbol
[ERROR] symbol: variable EntityUtils
[ERROR] location: class org.apache.ambari.view.Papi
[ERROR] /home/tmunson/ambari/ambari-views/examples/onefs-view/src/main/java/org/apache/ambari/view/isilon/Papi.java:[104,21] cannot find symbol
[ERROR] symbol: variable EntityUtils
[ERROR] location: class org.apache.ambari.view.Papi
[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
I thought I had included all the necessary dependencies in my pom.xml file for the view, but apparently this is not the correct way to do it:
<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">
<parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-view-examples</artifactId>
<version>2.1.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>onefs-view</artifactId>
<packaging>jar</packaging>
<name>Isilon OneFS View</name>
<version>2.1.3</version>
<url>http://maven.apache.org</url>
<properties>
<ambari.dir>${project.parent.parent.parent.basedir}</ambari.dir>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-views</artifactId>
<version>[1.7.0.0,)</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.3</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<phase>none</phase>
<goals>
<goal>rpm</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
So my questions are as follows:
1) Why won't Maven recognize the dependencies I've specified in my pom.xml file?
2) How would I go about making it recognize those dependencies? I'm kinda wondering if I just have the dependencies listed in the wrong place or something, but my understanding of how Maven works is that it will find the dependencies that you've specified in the pom.xml file and then download them and include them in your build. Since I'm including the dependencies but it's not recognizing them, I must be doing that wrong, but I have no clue what the right way to do it would be.
Thanks in advance for any help you all can offer!
If you define dependencies within the dependencyManagement section (like you did), those dependencies are not added to the project. They are only configured, so that POMs, which have this POM as parent, don't need to specify the version for a dependency (the dependency version becomes managed by the parent).
So in your case to resolve the problem, just remove the <dependencyManagement> and </dependencyManagement> tags.
I added the following dependency list in pom.xml for my Rest assured project with maven:
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
Now I am trying to run following sample code:
import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
import java.util.*;
import org.testng.Assert;
import org.testng.annotations.*;
public class TestNGTest1 {
private Collection collection;
#Test
public void testGetSingleUserProgrammatic() {
Response res = get("/service/single-user");
assertEquals(200, res.getStatusCode());
String json = res.asString();
JsonPath jp = new JsonPath(json);
assertEquals("test#hascode.com", jp.get("email"));
assertEquals("Tim", jp.get("firstName"));
assertEquals("Testerman", jp.get("lastName"));
assertEquals("1", jp.get("id"));
}
}
But this is throwing error while doing mvn test
Error is:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project GBAppAuomation: Compilation failure: Compilation failure:
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,2] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,2] error: cannot find symbol
Corresponding symbols are get etc, which rest assured uses.
As asked here is complete error message::
Here is the complete error message:: **
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # GBAppAuomation ---
[INFO] Compiling 1 source file to /home/jay/temp/GB_MVN_Proj/GBAppAuomation/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,1] error: cannot find symbol
[ERROR] class TestNGTest1
/home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,17] error: cannot find symbol
[ERROR] class TestNGTest1
/home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,2] error: cannot find symbol
[ERROR] class TestNGTest1
/home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,20] error: cannot find symbol
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.384s
[INFO] Finished at: Sat Jan 04 15:26:57 IST 2014
[INFO] Final Memory: 16M/202M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project GBAppAuomation: Compilation failure: Compilation failure:
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,1] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,17] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,2] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,20] error: cannot find symbol
The problem seems to be related with dependencies.
Were there any compilation errors in the IDE?
Because the interface Response from the line below (probably line 50 from the error)
Response res = get("/service/single-user");
belongs to package com.jayway.restassured.response, whereas the only imports in the class related to restassured are
import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.matcher.RestAssuredMatchers.*;
And the JsonPath class from (probably line 53 from the error)
JsonPath jp = new JsonPath(json);
belongs to package com.jayway.jsonpath and also not imported.
This package should be also included into the POM as a dependency:
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>0.9.1</version>
</dependency>
Please pay attention to the groupId. There are two of them available. The one you need for the Restassured jars is: io.rest-assured.
Currently, this is the latest version :
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>
If a newer version becomes available, all you need to do is to change the version number in the dependency from 3.0.3 to the new one.
For your information, there is no longer a need to add a standalone JsonPath dependency as it is now fully embedded in the rest-assured artifact as given as above