jBCrypt dependency not working - maven

I am using heroku embedded tomcat for my web application.
In my user registration page, I have function :
private static String hashPwd(String pwd) {
return BCrypt.hashpw(pwd, BCrypt.gensalt());
}
I added this dependency in pom.xml:
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
</dependency>
But when I try to git push my changes, I get an error:
cannot find symbol : variable BCrypt
at my function call. What am I missing?
My import looks like this:
import org.mindrot.*;

I found the problem. Apparently I had to import :
import org.mindrot.jbcrypt.*
instead of
import org.mindrot.*

Related

The STS couldn't understand my hateoas import and report error

I was building a RESTful service according to the official tutorial of Spring. I add the dependency as instructed, but the STS(Spring Tool Suite) couldn't figure out my function.
The STS couldn't understand methodOn() or lintTo() and keeps on giving errors,please help me with it.
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
Controller:
#GetMapping("/employees/{id}")
Resource<Employee> one(#PathVariable Long id) {
Employee employee = repository.findById(id)
.orElseThrow(() -> new EmployeeNotFoundException(id));
return new Resource<>(employee,
linkTo(methodOn(EmployeeController.class).one(id)).withSelfRel(),
linkTo(methodOn(EmployeeController.class).all()).withRel("employees"));
}
The import has been updated.
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

How I can resolve this problem (Class<SpringJUnit4ClassRunner> cannot be resolved to a type)?

I realized a simple projetc using spring and maven, my project contains an interface and 3 classes and the pom.xml file
Interface : CompactDisc.java
3 classes :
SgtPeppers.java that implements the CompactDisc interface
CDPlayersConfig.java is an empty class and contains the annotations of automatic scan
CDPlayersTest.java is a test class to test if the spring container works.
My problem is with #RunWith(SpringJUnit4ClassRunner.class) and #ContextConfiguration(classes=CDPlayersConfig.class), Eclipse suggests this proposition for the first annotation Class cannot be resolved to a type and it doesn't understand the second annotation.
You find here the code :
CompactDisc.java
package soundsystem;
public interface CompactDisc {
void play();
}
SgtPeppers.java
package soundsystem;
import org.springframework.stereotype.Component;
#Component
public class SgtPeppers implements CompactDisc{
private String title = "Sgt. Pepper's Lonely Hearts Club Band";
private String artist = "The Beatles";
public void play() {
System.out.println("Playing " + title + "by"+ artist);
}
}
CDPlayersConfig.java
package soundsystem;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
#Configuration
#ComponentScan
public class CDPlayersConfig {
}
CDPlayerTest.java
package soundsystem;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.jta.SpringJtaSynchronizationAdapter;
#RunWith(SpringJUnit4ClassRunner.class)//Here is my problem
#ContextConfiguration(classes=CDPlayersConfig.class)//Here is my problem
public class CDPlayerTest {
#Autowired
private CompactDisc cd;
#Test
public void cdShouldNotBeNull() {
assertNotNull(cd);
}
}
Dependencies im the pom file
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.0.5.RELEASE</version>
<scope>test</scope>
</dependency>
In Eclipse
Right Click on your Project
Select Maven
Select Update Project
Tick
Update project config from pom.xml
Refresh workspace
Clean projects
After doing that the required libraries should be available to Eclipse and you should be able to import the classes as required.
I can't see
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
in your import section. Also, maybe you should use SpringRunner.class instead of SpringJUnit4ClassRunner.class
Control+click on the class. Eclipse will open the file. Copy the package name. Create a new import statement and paste the package name + the class name. Problem solved.
If Eclipse does not open the file when you control+click, you don't have it on your class path or imported correctly.
You are missing the imports (import org.springframework...) for SpringJUnit4ClassRunner and ContextConfiguration. That's why they are not recognized.
You have to add dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
And then
import org.springframework.test.context.ContextConfiguration;
It's working in my Gradle project after complete some steps.
1st: Add dependency in build.gradle file ->
testImplementation 'junit:junit:4.13.2'
implementation 'org.springframework:spring-test:4.0.0.RELEASE'
2nd: Clean Gradle project using IDE or using command prompt -> Open command prompt -> Go to project location c:\gradle_projects\test_gradle>gradlew clean build -> Enter
3rd: Refresh Gradle project -> Open command prompt -> Go to project location c:\gradle_projects\test_gradle>gradlew --refresh-dependencies -> Enter
4th: Go to IDE -> right-click on project name -> Gradle -> Refresh Gradle Project
-> finally download jar files and import class

WebDrivermanager is not opening the browser

I am not able to open both IE and Chrome browsers using WebDriverManager dependency when i run as Maven test. I see that no error is thrown in console and test execution is inprogress even after several minutes.
I have a println statement before the opening the browser which gets printed in the console. Can someone please help me on this?where am I going wrong ?
I am using Spring Test Suite 3.3.0(instead of Eclipse), Java 1.8, Chrome Version - 67.0.3396.99, IE version - 11.0.60
Dependency in pom.xml
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
Java Class code
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;
public class SampleTest {
WebDriver driver;
#Test(priority = 2)
public void TC01()
{
System.out.println("Inside TC1");
WebDriverManager.iedriver().setup();
driver = new InternetExplorerDriver();
driver.get("https://www.google.com/");
}
#Test(priority = 1)
public void TC02()
{
System.out.println("Inside TC2");
}
}
Console
You can find a running example of Internet Explorer and WebDriverManager here. Moreover, take a look to the required configuration in Internet Explorer according to the Selenium doc.

How to work with selenium-chrome-driver in Maven without ChromeDriver.exe

I add the below dependency and code for Opening Chrome,but browser is not opening.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.50.0</version>
</dependency>
My code :-
package example;
import org.openqa.selenium.WebDriver;`
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class DepChrome {
#Test
public void testBrowser() {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
}
}
Add below dependency as below:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.0.0</version>
<!-- <scope>test</scope> -->
</dependency>
Source: copy new dependencies version from below URL:
https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
use below code :
WebDriver driver = null;
WebDriverManager.chromedriver().browserVersion("77.0.3865.40").setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("enable-automation");
options.addArguments("--no-sandbox");
options.addArguments("--disable-infobars");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
Basically below line of code did the trick, below code to download a specific version
WebDriverManager.chromedriver().browserVersion("77.0.3865.40").setup();
Required version you can get from below URL:
https://chromedriver.storage.googleapis.com/index.html
you can also use below code instead of above, if you are looking for latest dependencies present on above chromedriver URL
WebDriverManager.chromedriver().setup();
OR (Old Way)
You need to give path of chrome binary as below:
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
Download the binary of chrome from selenium site as below :-
http://chromedriver.storage.googleapis.com/index.html?path=2.21/
Now provide the path of the binary to selenium as :-
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
There is one more thing to take care. if you are using windows then use backward slash \\ and if you are using mac or linux then use forward slash // for setting up the path.
Hope it will help you :)
There are two ways.
Easiest way is to download chromedriver from the this location
Download chrome web driver
Then create a source folder in your project. (Ex : BrowserDrivers) and add downloaded library into this.
Then set the chrome driver path in the automation script using setProperty command as follow.
System.setProperty("webdriver.chrome.driver", "BrowserDrivers/chromedriver.exe");
But there is another way. This is more suited for maven build.
Add following dependencies in to the POM.xml file.
There are 2 dependencies. One for Chrome Driver. But to use chrome driver dependency you have to add webdrivermanager dependency. It is compulsory dependency for browser driver. So always you have to add both of them.
For more details refer this link Github Webdriver manager link
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.2.5</version>
</dependency>
And add chrome driver dependency also.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.50.0</version>//Your chrome driver version
</dependency>
Then in your automation script use this line instead of System.setProperty command to declare chrome driver.
ChromeDriverManager.getInstance().setup();
UPDATE: the use of ChromeDriverManager is deprecated, use this instead:
import static io.github.bonigarcia.wdm.DriverManagerType.CHROME;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
WebDriverManager.getInstance(CHROME).setup();
Check below code -
package example;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class DepChrome {
#Test
public void testBrowser() {
WebDriver driver;
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("https://google.com");
String title = driver.getTitle();
System.out.println(title);
driver.quit();
}
}
With the following two maven dependencies, you do not need to set system properties at all, this should work
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdriver-manager.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium-chrome-driver}</version>
</dependency>
WebDriver driver;
#BeforeSuite
public void setUp(){
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("http://www.ebay.in");
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
}
In Maven, with the use of ChromeDriver.exe:
import static io.github.bonigarcia.wdm.DriverManagerType.CHROME;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.testng.annotations.Test;
public class MavenTest {
#Test
public void TestMaven()
{
System.setProperty("webdriver.chrome.driver", "D:\\Sumit_Backup\\Automation\\Workspace\\Maven\\src\\Browser\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("http://testng.org/doc/maven.html");
driver.manage().window().maximize();
}
}

TilesConfigurer is deprecated ?? How I use tile2.2 in spring MVC 3.1?

I try to integrate Spring MVC 3.1 with Apache Tile2.2 but I found this error
Error creating bean with name 'tilesConfigurer' defined in ServletContext resource [/WEB-INF/tiles-context.xml]: Invocation of init method failed
so I search it in google and I found in Apache Tile2 structure had change or deprecated but spring mvc 3.1 still use old structure. (Someone said We must modify the class or etc.)
These are my lib I used:
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-el-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
adn spring mvc
org.springframework.aop-3.1.0.M1.jar
org.springframework.asm-3.1.0.M1.jar
org.springframework.aspects-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context.support-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1.jar
org.springframework.instrument.tomcat-3.1.0.M1.jar
org.springframework.instrument-3.1.0.M1.jar
org.springframework.jdbc-3.1.0.M1.jar
org.springframework.jms-3.1.0.M1.jar
org.springframework.orm-3.1.0.M1.jar
org.springframework.oxm-3.1.0.M1.jar
org.springframework.test-3.1.0.M1.jar
org.springframework.transaction-3.1.0.M1.jar
org.springframework.web.portlet-3.1.0.M1.jar
org.springframework.web.servlet-3.1.0.M1.jar
org.springframework.web.struts-3.1.0.M1.jar
org.springframework.web-3.1.0.M1.jar
Anyone know how I fix this ? It will be useful to me.
If you import from org.springframework.web.servlet.view.tiles3 package you will not get any depricated issue but if you import from org.springframework.web.servlet.view.tiles2 it is depreciated. I solved the issue by changing imports.
Configuration class
package mum.waa;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesView;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
#Configuration
public class TilesConfiguration{
public TilesConfigurer tilesConfigurer()
{
final TilesConfigurer configurer = new TilesConfigurer();
configurer.setDefinitions(new String[] { "WEB-INF/tiles.xml" });
configurer.setCheckRefresh(true);
return configurer;
}
#Bean
public TilesViewResolver tilesViewResolver() {
final TilesViewResolver resolver = new TilesViewResolver();
resolver.setViewClass(TilesView.class);
return resolver;
}
}
Dependencies
<!-- Apache Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.7</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.7</version>
</dependency>
<!-- Apache Tiles -->
(Answered by the OP in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
solution:
This is not error by deprecated it's about jar file that didn't right version.
I solved by find right jar to my web application
this is my jar
commons-beanutils-1.8.3.jar
commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-core-1.8.3.jar
commons-digester-2.1.jar
jcl-over-slf4j-1.6.3.jar
slf4j-api-1.6.3.jar
slf4j-log4j12-1.6.3.jar
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
For some people get lost like me, Mart

Resources