cannot resolve "org.h2.tools.Server"? - java

I downloaded some code from net and opened it in Eclipse. The problem is
my Eclipse says
The import org.h2 cannot be resolved
for following code:
import org.h2.tools.Server;
I am learning Java and that was a sample code. I'm using jdk1.8.0_40. I cleaned my project but it still there!

Personally, I changed the h2 dependency on pom.xml
It was
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
I removed the scope and it found the Server package
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
A good explanation on why this is happening on runtime here:
Maven : what is the "runtime" scope purpose?

Actually, this means your code requires a so called 3rd party library which is not part of the jdk. H2 is a java based database. To remove this error, download the current version of the h2 database driver and do the following in eclipse - open context menu on your project, choose the properties ( last entry). Search for "build path", choose the third tab and add the download driver (should be a jar file, maybe packed in a zip) to your project.
Cannot better describe this now, I am on my mobile.

Related

Encountering a Mysql Connection problem java

The error I am getting is PY4JAVAERROR :
an error occurred while calling o313.load: Java.lang.classnotfoundexception: com.mysql.jdbc.Driver
has anyone encountered this before?
Place mysql-connector jar in your classpath.
That occurs when you don't have a MySQL connector in your classpath. If you are using a maven project you can try adding the dependency to your pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
If you are not using a dependency management tool like Maven or Gradle you can download the jar online and then add it to your classpath. Here is the link.
https://dev.mysql.com/downloads/connector/j/
Remember to do a bit of research for the correct versions before you download.
Either of the two options will definitely work.
It seems the mysql connectivity library is not included in the project. Solve the problem following one of the proposed solutions:
MAVEN PROJECTS SOLUTION
Add the mysql-connector dependency to the pom.xml project file:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version> // your desired version
</dependency>
Here you are all the versions: https://mvnrepository.com/artifact/mysql/mysql-connector-java
ALL PROJECTS SOLUTION
Add the jar library manually to the project.
Right Click the project -- > build path -- > configure build path
In Libraries Tab press Add External Jar and Select your jar.
You can find zip for mysql-connector here
Explanation:
When building the project, java throws you an exception because a file (the com.mysql.jdbc.Driver class) from the mysql connectivity library is not found. The solution is adding the library to the project, and java will find the com.mysql.jdbc.Driver

Java Library's Parameter Name differs between projects

I am developing Web Services with the following stacks:
Spring Boot with Spring Security
Maven -> add dependency from Maven Repo on pom.xml
Vs Code
Two Project (Two VS Code Windows): Production Development & Testing
List item
Desc:
In using 'SessionRegistry', when I try to see what is inside the 'SessionRegistry.class', the name of the parameters are as the image below:
Problem
Image_1.1) shows no indication on the purpose of the parameter as encircled on the image on the production project.
Stats on Testing Project, and this is my actual Expectation:
Expectation Image_1.2) has appropriate name of the parameter and it shows sense what is the purpose of the parameter.
++ Both of the Project is referring the same dependency thru pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
What I have already tried:
I have even tried to remove and download all of the dependencies at the Users/../.m2/repository
Wondered if the outdated version was the cause... so even tried to indicate the latest version enumerated on official maven repository website with the follwoing version:
--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.6.3</version>
</dependency>
Awaiting for your advise with an advance grafulness.
You have not provided the source code for the library. Without the source, the IDE will still show the prototype (since that can be determined from the .class file) but it will make up names for the arguments, as you see.
Refer to the VSCode documentation to learn how to attach source jars.

How to download files from Gitlab account using java

I am writing one utility job in java to download JSON files from particular URL of Gitlab account and further process them according to requirement. I tried to do same using java-gitlab-api dependency. However, even after including below maven dependency,
I get error as :
Missing artifact org.gitlab:java-gitlab-api:jar:1.1.8-
The import org.gitlab cannot be resolved.
Maven dependency I am using is :
<dependency>
<groupId>org.gitlab</groupId>
<artifactId>java-gitlab-api</artifactId>
<version>1.1.8-SNAPSHOT</version>
</dependency>
I tried to update, clean maven project but nothing worked. Anyone has an idea of how can I rectify issues and download files from gitlab account.
Use appropriate maven java-gitlab-api version(s). There is most recent version is available too.
https://mvnrepository.com/artifact/org.gitlab/java-gitlab-api/1.1.8
https://mvnrepository.com/artifact/org.gitlab/java-gitlab-api
<!-- https://mvnrepository.com/artifact/org.gitlab/java-gitlab-api -->
<dependency>
<groupId>org.gitlab</groupId>
<artifactId>java-gitlab-api</artifactId>
<version>1.1.8</version>
</dependency>

Cannot resolve symbol 'Assertions' <-- Error message when trying to use AssertJ in IntelliJ

Similar to some other Questions, I find IntelliJ mysteriously refuses to recognize AssertJ library. I am asking again as (a) I have tried the various suggestions, and (b) I have a very simple example anyone can try themselves.
In IntelliJ 2018 and IntelliJ 2019 pre-release, I create a new project using the Maven archetype maven-archetype-quickstart version 1.4.
AssertJ 3 requires Java 8. So I changed these two lines in the POM for 1.7 to 11.
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
I add this to the POM:
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>
Using the Maven panel in IntelliJ, I executed a clean and install.
Seems good. I verify the org.assertj:assertj-core:3.11.1 library appears in the Project panel of IntelliJ. The app runs, with Hello World appearing on the console in IntelliJ.
In the App.java file, I add this import statement.
import static org.assertj.core.api.Assertions.* ;
Error reported in the IDE editor:
Cannot resolve symbol 'Assertions'
Some people suggest a corrupted Maven cache. So I quit IntelliJ, and I delete the .m2 folder in my home folder. I re-open my project in IntelliJ, and re-execute the Maven clean & install. Many things are downloading, so I know the Maven cache is indeed being recreated.
Yet, still the error in my editor, Cannot resolve symbol 'Assertions'.
No Java Modules involved, as the quickstart archetype has not yet been updated for that.
Delete <scope>test</scope>
This topic was addressed in a closed ticket # 520 on the AssertJ issue tracker.
When a Maven dependency carries a scope element with a value of test, that means you cannot use that library outside of your test-specific source package/folder.
If you are trying to call AssertJ from code in your example project’s src/main/java/… folder hierarchy, you will see that error. If you call AssertJ from src/test/java…, you will see success.
To enable AssertJ in the src/main/java/… folder hierarchy, delete the scope element in your POM dependency. So this:
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>
…becomes this:
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
</dependency>

Maven dependency for javax.ejb.jar into .m2 directory

I cant find javax.ejb.jar in my .m2 dirctory, I need this jar for import javax.ejb.Schedule; , here is my pom file entry.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
I am not sure if it will work or not, or its a right way to do things. Can some one please help to make a change in the POM file so that it downloads javax.ejb.jar into the .m2 directory.
Updated
by .m2 I mean in the repository directory in the correct folder
hierarchy (What ever it is).
Why? We have multiple sub projects (In eclipse workspace), In order to resolve dependency we use M2_REPO/path/to/the/required_library_file.jar, Now theses projects are part of code bases, Every developer download the source code, Maven download all jar to the repository directory(of the developer using any OS/Platform). This relative path from M2_REPO helps developer to have consitenat code (for eclipse project). Otherwise everyone will be adding their own path.
If it still doesn't make sense, here is what I want, Please give me an entry for POM file which download the javax.ejb.jar file into .m2 directory what ever the sub path is.
I have to include this jar in every project manually (And every developer needs to them as well from what ever directory have glassfish (C: , D:, E:, or /home/glassfish/modules/)
D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar
where rest of the jars in each project are included as M2_REPO/path/to/jar which makes less no changes in the code base to commit.
M2_REPO/javax/ejb/ejb-api/3.0/ejb-api-3.0.jar
M2_REPO/javax/enterprise/cdi-api/1.0-SP1/cdi-api-1.0-SP1.jar
M2_REPO/javax/inject/javax.inject/1/javax.inject-1.jar
etc etc
I think I hear what you mean now :)
The maven dependency you specify
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
which you have in .m2/repository/javax/ueb/ejb-api/3.0/ejb-api-3.0.jar does not contain the class/interface javax.ejb.Schedule.
But you found the jar-file in your glassfish server, which does contain javax.ejb.Scheduleand its name is D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar and now you ask how to get that into the pom?
Well, the Java EE APIs and their official jars in maven are somewhat a study in disharmony.
If you run a search on maven central you will find multiple jars containing exactly that class. You will probably note that all appserver vendors provide their own edition of every aspect of every api in every version.
You should be able to find a jar with the javax.ejb module from glassfish in version 3.1.2
http://search.maven.org/#artifactdetails|org.glassfish|javax.ejb|3.1.2|jar
in which case the dependency would be
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
I found another artifactId here, though maven has your version too.
A (very) weird maven caching problem? Then it might work tomorrow.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
Though this is a new version, for compilation it should do.
You may need to provide the repository location in your pom.xml file or in .m2/settings.xml file for the required jar to get downloaded into .m2 directory.
The dependency is declared as provided what means that the container will provide it.
What container are you using? I think Tomcat/Jetty won't provide that jar as it seems so Java EE. In that case just change the scope to compile.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
More info about dependency scopes:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

Categories