This is my first Java project using Maven (Jakarta and PostgreSQL dependencies) in which I am struggling with many basic compiling issues. I am also using the newest VSCode as an editor.
First issue
The terminal tries to find Main.java
at '...\Projeto-POO-2022.2' when it should actually access '...\Projeto-POO-2022.2\javarental\src\main\java\poo' where the file currently lies.
I have already tried manually setting up terminal.integrated.cwd
to access the right path with no success.
Second issue
Even using 'cd javarental\src\main\java\poo' to access the right path and then running the project with 'javac Main.java' the following errors come up:
Main.java:3: error: package jakarta.persistence does not exist
import jakarta.persistence.EntityManager;
^
Main.java:4: error: package jakarta.persistence does not exist
import jakarta.persistence.EntityManagerFactory;
^
Main.java:5: error: package jakarta.persistence does not exist
import jakarta.persistence.Persistence;
^
Main.java:7: error: package poo.models does not exist
import poo.models.Usuario;
^
Main.java:11: error: cannot find symbol
Usuario user = new Usuario();
^
symbol: class Usuario
location: class Main
Main.java:11: error: cannot find symbol
Usuario user = new Usuario();
^
symbol: class Usuario
location: class Main
Main.java:19: error: cannot find symbol
EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
^
symbol: class EntityManagerFactory
location: class Main
Main.java:19: error: cannot find symbol
EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
^
symbol: variable Persistence
location: class Main
Main.java:20: error: cannot find symbol
EntityManager em = emf.createEntityManager();
^
symbol: class EntityManager
location: class Main
9 errors
For addition, this is the section of code Main.java
:
package poo;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import poo.models.Usuario;
public class Main {
public static void main(String[] args) {
Usuario user = new Usuario();
user.setEmail("[email protected]");
user.setNomeUsuario("user_3");
user.setNome("User");
user.setSenha("senha");
user.setCpf(123);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
EntityManager em = emf.createEntityManager();
em.close();
}
}
And this is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>poo</groupId>
<artifactId>javarental</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>javarental</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.1.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.4.0</version>
</dependency>
</dependencies>
</project>
Don't know if it has something to do with but I've imported and synced this project straight from GitHub. I've also tried rebuilding it a few times with no luck. Any help would be appreciated.
CodePudding user response:
For the first problem, I have no idea.
For the second problem, it's possible that your pom.xml
has the wrong dependencies.
Also, I love the package name. (poo)
CodePudding user response:
Somehow I got it working through the following steps:
- Delete the project folder;
- Remove any invalid characters from the new project folder path;
- Create a new folder;
- Clone once again the repository from GitHub.