无法启动Maven服务 – 找不到类 #

huangapple go评论59阅读模式
英文:

Cannot start maven service - Class not found #

问题

好的...作为开发者的第一次,我不知道如何修复这个错误。

我在使用Maven命令和Intellij时遇到了问题。

(重要)

所有本地项目上的Maven命令都无法运行,返回错误:

无法找到或加载主类#,java.lang.ClassNotFoundException:#

有关错误消息中的“#”的详细信息。

我的pom.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 https://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.3.4.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>garantia.safra</groupId>
	<artifactId>gateway</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>gateway</name>
	<description>description</description>

	<properties>
		<java.version>11</java.version>
		<start-class>garantia.safra.gateway.GatewayApplication</start-class>
	</properties>

	<dependencies>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>

		<!-- 其他依赖项... -->

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

我尝试删除了.m2/repository文件夹,但没有起作用。

我尝试了“设置 > 构建、执行、部署 > 构建工具 > Maven > 导入”,将导入设置为“项目的JDK”,但没有起作用(我正在使用JDK 11,之前可以工作)。

我尝试通过Intellij更新Maven仓库(远程和本地),现在我从远程仓库收到一个错误(找不到任何导入的包类)。

我唯一解决它的方法是将项目重新创建为一个新项目,然后添加所有的类和pom.xml,但当我添加了配置文件后,它再次出错。

我在生产中使用代理(.maven/jvm.config)

# -Dhttp.proxyHost=<proxy_host>
# -Dhttp.proxyPort=<proxy_port>
# -Dhttps.proxyHost=<proxy_host>
# -Dhttps.proxyPort=<proxy_port>

但是这些行都是被注释掉的,对吗?

还有application.properties文件:

server.address=0.0.0.0

所以...这是一个非常烦人的问题,我已经没有了想法。也许我会尝试重新创建项目,并重新导入每个文件,以查看哪个文件是有问题的,但如果有人之前遇到过这个问题并修复了它... 怎么办?

英文:

Ok...for the first time in my life as a Developer I have no Idea how to fix this error.

I'm having issues with Maven commands and Intellij.

(IMPORTANT)

All maven commands on local project isn't working and returns the error:

cannot find or load main class #, java.lang.ClassNotFoundException: #

Detail for the "#" on the error message.

My pom.xml file is:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;parent&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
		&lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
		&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
	&lt;/parent&gt;
	&lt;groupId&gt;garantia.safra&lt;/groupId&gt;
	&lt;artifactId&gt;gateway&lt;/artifactId&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;name&gt;gateway&lt;/name&gt;
	&lt;description&gt;description&lt;/description&gt;

	&lt;properties&gt;
		&lt;java.version&gt;11&lt;/java.version&gt;
		&lt;start-class&gt;garantia.safra.gateway.GatewayApplication&lt;/start-class&gt;
	&lt;/properties&gt;

	&lt;dependencies&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
			&lt;artifactId&gt;jjwd&lt;/artifactId&gt;
			&lt;version&gt;0.9.1&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
			&lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
			&lt;version&gt;2.3.0&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
			&lt;scope&gt;runtime&lt;/scope&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
					&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
			&lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;


	&lt;/dependencies&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

&lt;/project&gt;

I tried to delete .m2/repository folder but it didn't work.

I tried to 'Settings > Build, execution, deployment > Build Tools > maven > Importing' and set the import as 'project JDK' but it didnt work. (I'm using JDK 11, and it was working before)

I tried to update the maven repositories by Intellij (remote and local) and now I have a error from remote repository (can't find any imported package classes)

The only thing I did that solve it once, was recreate the project as a new one and add all the classes and pom.xml, but when I added my configuration files it broke again.

I'm using a proxy from production (.maven/jvm.config)

# -Dhttp.proxyHost=&lt;proxy_host&gt;
# -Dhttp.proxyPort=&lt;proxy_port&gt;
# -Dhttps.proxyHost=&lt;proxy_host&gt;
# -Dhttps.proxyPort=&lt;proxy_port&gt;

But the lines are all commented right?

And application.properties:

server.address=0.0.0.0

So...This is being a very anoying problem, and I'm lack of ideas. Maybe I'm gonna try to recreate the project AGAIN and reimport each file to see which is the broken one, but if someone had this issue before and fixed it...how?

答案1

得分: 1

删除.maven/jvm.config文件,它会被直接加载并添加到命令行中,不支持注释语法。

英文:

Empty or delete .maven/jvm.config file, it's loaded directly and added to the command line, the comments syntax is not supported.

huangapple
  • 本文由 发表于 2020年10月16日 03:26:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64378451.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定