Eclipse is not importing com.google.api.client. imports? - java

I am trying to implement Google's calendar API into my spring boot project in eclipse. I am following this Java tutorial from the Google Developers' website
I am on step 3 where I am to copy in code, however there are errors under all of the Google API imports:
The error I get:
The import com.google cannot be resolved
The Gradle file leading to the error:
UPDATE:
I added the following to the Pom file and it removed almost all of the import errors:
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev224-1.22.0</version>
</dependency>
However, the following two imports still have errors:
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;

You cannot use both gradle and maven together. Use either gradle or pom.
Remove the gradle build file and add the dependencies in the pom.xml as you mentioned.
Then go to maven ==> Update Project
And that should download the dependencies and fix the errors.

You have to add all the dependencies to the POM file:
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev305-1.23.0</version>
</dependency>

I think issue here is the way eclipse handle gradle project
Use Eclipse Version: Oxygen Release (4.7.0)
install https://marketplace.eclipse.org/content/egradle-ide#group-details
re import your project as gradle project
==
delete pom.xml, I think eclipse confuses between gradle project vs maven project

Related

package org.springframework.cloud.netflix.zuul does not exist

I am moving some test code from an older jHipster project to a new one. The old project uses the org.springframework.cloud.netflix.zuul library, specifically org.springframework.cloud:spring-cloud-netflix-core:1.3.0.RELEASE .
I put the below in my new project's pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
However, it seems to be pulling in org.springframework.boot:spring-boot:2.2.5.RELEASE. This release does not contain zuul in it however, as this code fails import org.springframework.cloud.netflix.zuul.
Does anyone know a fix or workaround?
Old library.
org.springframework.cloud:spring-cloud-netflix-core:1.3.0.RELEASE
My new project is using
org.springframework.boot:spring-boot:2.2.5.RELEASE
UPDATE:
Sorry I updated my question - my pom file already has this code. But it is very weird to me that even though I put to 1.3.0, I can see in my maven dependencies that it's pulling in 2.2.5. Also when I right click my project, I see maven - reimport and maven - generate sources etc.. I don't see a update project. And clicking both of those doesn't seem to downgrade it to 1.3.0
If you update your pom.xml file your problem would solve.
In your pom.xml file you'll see dependencies tag you need to add the library you want and then right click your project and say maven -> update project
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
</dependencies>
Add following dependency to your pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
Upgrading spring-boot to >= 2.5 requires some extra configuration in order for Zuul to keep working, see:
https://gist.github.com/aldobongio/6a22f49863c7a777612f7887bbb8fd1d

Maven using wrong dependency version

The dependency version I want to use is 4.5.0 as specified in my pom.xml
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.5.0</version>
</dependency>
However, when I run mvn clean install -DskipTest=true. Maven will download and use version 4.2.2.
libraries
I tried searching in the entire project thinking maybe there are other files(in this case pom.xml) that specify the version to 4.2.2 but found nothing.
Has anybody encountered this issue before? I'm new to Java and I can't think of any other reason as to why this is happening.
Look at the output of mvn dependency:list. It will list you all dependencies of the project with their respective versions.
This is the truth. If your Eclipse or IntelliJ or whatever list something else, they are most certainly wrong/outdated.

How to resolve Microsoft Azure dependencies on Eclipse

I'm trying to follow "How to run a compute-intensive task in Java" tutorial.
However, I'm stuck on the following step:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-java-run-compute-intensive-task/#how-to-create-a-java-application-that-performs-a-compute-intensive-task
Eclipse shows an error saying that these dependencies can't be resolved:
import com.microsoft.windowsazure.services.core.Configuration;
import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.serviceBus.*;
import com.microsoft.windowsazure.services.serviceBus.models.*;`
I'm using Eclipse and I've downloaded the Azure toolkit for Eclipse.
Here's how my Eclipse project looks like:
The code is simply a copy-paste of TSPSolver.java.
Per my experience, the issue was caused by missing some dependent libraries that you can try to add them via configure the Java Build Path or configure the pom.xml file in the Maven project to resolve it.
For the first way, adding the dependent libraries via configure the Build Path. You can download these libraries and their dependencies from the link.
Right click on the project name, then select Build Path and click Configure Build Path.
Add these jar files via click Add External Class Folder
For the second way, adding the maven dependencies in the pom.xml file.
Convert the current normal Eclipse Project into a Maven project.
Open the pom.xml file in the project and add the below content from link1 & link2.
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-core</artifactId>
<version>0.9.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>0.9.7</version>
</dependency>
</dependencies>
For those looking now, latest version are as follows:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>3.6.7</version>
</dependency>

Cannot import GraphDatabaseFactory

I am very new to Neo4j and I want to get started with an embedded Neo4j in a Java Application.
I try to create an HelloWorld Application like the following:
https://neo4j.com/docs/java-reference/current/#tutorials-java-embedded
You can find the source code here:
https://github.com/neo4j/neo4j/blob/3.1/manual/embedded-examples/src/main/java/org/neo4j/examples/EmbeddedNeo4j.java
I created a new maven project and added org.neo4j:neo4j 3.0.3 as a dependency. Unfortunately I cannot import "org.neo4j.graphdb.factory.GraphDatabaseFactory", all other imports seem to be ok.
Now I figured out, that the import is working for version "3.1.0-SNAPSHOT" of the neo4j dependency.
Here you can find the relevant part of my pom-file:
<dependencies>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
Because I want to use a stable version, I want to achieve this with version 3.0.3 as well, but I cannot find something that this factory is depending on this version or how you should do it at version 3.0.3. Can somebody provide information about this?
The dependency you should include in your pom.xml is
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.0.3</version>
</dependency>
As I see you already included the right dependency. Then I guess something went wrong during the resolving. Therefore purge your local repository and resolve the dependency again with following command
mvn dependency:purge-local-repository -Dinclude=org.neo4j:neo4j
If it's still not working you have to check if you are resolving the artifact from the maven central repository or somewhere else.

Exception in thread "main" cucumber.runtime.CucumberException: No backends were found

I am developing my Selenium-JVM framework with Cucumber and while running my first feature got below error.
Please help.
How did I launch the feature -
Right click on feature file
Select Run As -> Cucumber Feature
Immediate Exception -
Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
at cucumber.runtime.Runtime.<init>(Runtime.java:78)
at cucumber.runtime.Runtime.<init>(Runtime.java:67)
at cucumber.runtime.Runtime.<init>(Runtime.java:63)
at cucumber.api.cli.Main.run(Main.java:24)
at cucumber.api.cli.Main.main(Main.java:16)
What I have in code -
Launcher.java -
package cucumber;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(format={"pretty","json:target/"} , features="/src/test/java/cucumber/features")
public class Launcher {
}
Feature file -
Feature: it works demo
Scenario: First test
Given this is my step
When this is my second step
Then this is my final step
List of Dependencies added to list -
cucumber-core-1.1.8
cucumber-html-0.2.3
cucumber-java-1.1.8
cucumber-junit-1.1.8
cucumber-jvm-deps-1.0.3
gherkin-2.12.2
hamcrest-all-1.3
junit-4.11
selenium-api-2.42.2
selenium-firefox-driver-2.42.2
selenium-java-2.42.2
selenium-remote-driver-2.42.2
selenium-support-2.42.2
My JVM - 1.7
Only this much is available in project.
Please help.
Make sure you're adding below dependencies for Maven project:
You can replace version to the latest or the required version:
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.0</version>
</dependency>
This error is thrown when no 'backends' are found on the classpath. There is a 'backend' for each supported language (e.g. cucumber-java, cucumber-groovy etc.)
It's probably a classpath error, although if cucumber-core and cucumber-java are in the same location that does seem strange.
Used the latest and same version for all dependencies and it works fine.
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>6.11.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.11.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.11.0</version>
</dependency>
</dependencies>
You can try the cucumber-java-1.2.4 at https://mvnrepository.com/artifact/info.cukes/cucumber-java/1.2.4.
I found that trying a previous version of the same JAR file worked for me.
I guess this may solve for other people as well. In case it does not, please add another answer.
Let me know if it worked for you and saved some valuable time :-)
Writing in 2020, though enough discussion has already gone on this topic. Still if it helps someone. For me the issue got resolved with same version of
cucumber-java
cucumber-junit
cucumber-core
dependencies
snippet of my POM
io.cucumber
cucumber-java
6.4.0
io.cucumber
cucumber-core
6.4.0
io.cucumber
cucumber-junit
6.4.0
compile
You are not providing the path of the step definition class
Add glue in the cucumber options may be it will help.
#RunWith(Cucumber.class) #CucumberOptions(
features ="Path of the feature file",
glue = {"path of step definition class or package "},
format={"pretty","json:target/"},
dryRun = true,
strict = true,
monochrome = true )
I got this same error message when trying to run a Cucumber feature file in Eclipse.
These steps worked for me:
Updated my pom.xml file with the latest and same version of the following libraries.
cucumber-junit - 1.2.6
cucumber-java - 1.2.6
Also I updated 'junit' to the latest version
Here is the fix:
in eclipse projects add the following in the .project file
<buildSpec>
...
<buildCommand>
<name>cucumber.eclipse.steps.jdt.stepsBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
...
<nature>cucumber.eclipse.steps.jdt.stepsNature</nature>
</natures>
If this did not fix the issue,
add the dependency
cucumber-java
in the project classpath or change the version of the jar to latest or n-1
i had pom in my dependency for cucumber-java. Once i removed that worked fine
I have updated my pom.xml file with the latest version of following libraries. It works for me.
junit
cucumber-java
cucumber-junit
Make sure you are using the correct version of junit, cucumber-java, cucumber-junit. It should not be like you are using some older version of junit and latest versions of cucumber junit and java. I have list down the dependencies which I have used. You can try these.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.7.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.7.0</version>
</dependency>
The error simply says that cucumber is not configured properly on your device.
This can be because of missing dependencies or the dependencies are not loaded properly.
Check for the dependencies first and then save all, close the editor, and then reopen it.
Try to run again and check.
Removed Cucumber Core dependency from POM.XML it is working fine
Commenting in 2021. This might help someone.
The issues is simple, cucumber groupid has been changed to >io.cucumber< so if you are still using >info cukes< you will be getting exceptions. That is why when you update your cucumber java to the latest it solves the issue bc the latest groupid comes as io.cucumber. You can as well change all the groupid info cukes in your pom.xml to io.cucumber. This will solve the issue
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
Keep only three tags (groupId, artifactId and version) in your dependencies. Delete <scope> and other additional tags in pom.xml and then try.
Errors on running Cucumber Feature
Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
Solution
Most probably this means that your cucumber-java version and java version on your machine is not compatible with each other. First, check Java Version on your machine by going through this article How to check Java/JDK Version Installed on your Machine.
On my machine, I have Java 1.8.0 with cucumber-Java8-1.2.5 and it did not work. When I degraded my cucumber java version to cucumber-Java-1.2.5, it worked fine for me. Just make sure that first, you remove the cucumber-java which did not work for you from Project build path >> Libraries and then add new.
It can also be caused by having 2 backend: for example:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.8.0</version>
<scope>test</scope>
</dependency>
and
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
Also make sure you have compatible versions
I encountered this same error message when trying to run a Cucumber feature file in Eclipse ("No backends were found. Please make sure you have a backend module on your CLASSPATH").
What fixed it for me was going into my pom.xml and changing the cucumber-java and cucumber-junit versions away from 1.2.5 (per their documentation) to 1.2.0.
I'm not 100% sure if I'm ignoring a real issue by doing this or not. Here is more information about my setup:
Windows 10
Eclipse Neon (4.6.0)
Apache Maven 3.5.0
Java 1.8
I verified via quick commands that java and maven are installed successfully and running on my machine. I also verified that Maven pulled in the cucumber-java, and cucumber-core jars in my Eclipse project. Odd.
Adding the following dependency I got resolved this issue
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.6</version>
</dependency>

Categories

Resources