eclipse springboot运行helloworld错误: 找不到或无法加载主类 xxx.xxx.xxx
这个错误,在网上搜找了好久,说是什么jar包冲突,什么环境配置,我经过验证均是正确的,javac java java -version 都没问题,环境变量也OK,各种解释均没有能够解决我的问题,最后好一顿折腾,解决了
shiro 的测试方法
package com.sharp.forward; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.realm.SimpleAccountRealm;
import org.apache.shiro.subject.Subject;
import org.junit.Before;
import org.junit.Test; public class JavaShiroTest extends ShiroApplicationTests{ SimpleAccountRealm realm = new SimpleAccountRealm("simpleRealm");
@Before
public void add() {
realm.addAccount("张三", "123456");
} @Test
public void contextLoads() {
}
@Test
public void testAuthenticate() {
// 三要素,SecurityManager,subject,realm
DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
// SecurityManage设置realm与数据库或缓存相连接
defaultSecurityManager.setRealm(realm);
// SecurityUtils设置SecurityManager可以与主题subject相连接
SecurityUtils.setSecurityManager(defaultSecurityManager);
// 获取主题,并通过secutityUtil将securityManager和realm联系起来,
Subject subject = SecurityUtils.getSubject();
// 提交主题是通过token提交的
UsernamePasswordToken token = new UsernamePasswordToken("张三", "123456");
subject.login(token);
System.out.println("subject.isAuthenticated(): "+subject.isAuthenticated()); } }
在测试类里面的测试方法报错,
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testAuthenticate], {ExactMatcher:fDisplayName=testAuthenticate(com.sharp.forward.JavaShiroTest)], {LeadingIdentifierMatcher:fClassName=com.sharp.forward.JavaShiroTest,fLeadingIdentifier=testAuthenticate]] from org.junit.internal.requests.ClassRequest@73c6c3b2
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:80)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:71)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
然后在主类中写了一个main查看是否报错
然后找解决办法,
说明首先,我是创建的springboot工程,创建的时候,因为之前选择版本的问题,出来的项目总不是完整的项目,需要修改版本,可能是这个原因导致的一些配置发生了变化,现在先看一下我的创建过程,我的项目都是自己搭建的私服
当出现不完整的项目的时候,就把项目的版本修改为适应的版本就可以出来了,可能是由于记忆了,
之前出现题目中的问题是运行其他项目中突然出现的,于是我仍然在同样的环境下建的项目但运行helloworld
就是main方法打印helloworld,控制台同样出现了错误:找不到或无法加载主类的提示,
最终解决办法是:先run build install 此时发现不能成功,提示用的是jre不是jdk,然后修改为jdk,再次运行一切都好了,
然后我再去创建项目,除了将https改为http外,其他的完整项目均能一次加载,不需要修改版本了。
这样解决了,
但是我又重新复现了一下这个问题,发现单单修改了这里有时候还不行,maven install 仍然报jre而不是jdk,同样又出现上述问题,于是我又修改如下地方
项目右键属性,下方修改为jdk,
再次 install 然后再去运行helloworld和测试,完美解决,看来还是jdk在作怪。
测试运行结果
junit变为绿条了
控制台打印结果如下
16:41:35.128 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.sharp.forward.JavaShiroTest]
16:41:35.135 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
16:41:35.147 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
16:41:35.171 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.sharp.forward.JavaShiroTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
16:41:35.189 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.sharp.forward.JavaShiroTest], using SpringBootContextLoader
16:41:35.199 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.sharp.forward.JavaShiroTest]: class path resource [com/sharp/forward/JavaShiroTest-context.xml] does not exist
16:41:35.200 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.sharp.forward.JavaShiroTest]: class path resource [com/sharp/forward/JavaShiroTestContext.groovy] does not exist
16:41:35.200 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.sharp.forward.JavaShiroTest]: no resource found for suffixes {-context.xml, Context.groovy}.
16:41:35.201 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.sharp.forward.JavaShiroTest]: JavaShiroTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
16:41:35.284 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.sharp.forward.JavaShiroTest]
16:41:35.397 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:\worksheet\shiro\target\classes\com\sharp\forward\ShiroApplication.class]
16:41:35.404 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.sharp.forward.ShiroApplication for test class com.sharp.forward.JavaShiroTest
16:41:35.538 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.sharp.forward.JavaShiroTest]: using defaults.
16:41:35.540 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
16:41:35.592 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
16:41:35.593 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
16:41:35.593 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@6e171cd7, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@402bba4f, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@795cd85e, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@59fd97a8, org.springframework.test.context.support.DirtiesContextTestExecutionListener@f5ac9e4, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@123ef382, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@dbf57b3, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@384ad17b, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@61862a7f, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@441772e]
16:41:35.596 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.596 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.598 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.598 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.672 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.672 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.676 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.676 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.677 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.682 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.690 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@9f116cc testClass = JavaShiroTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@12468a38 testClass = JavaShiroTest, locations = '{}', classes = '{class com.sharp.forward.ShiroApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@76b0bfab, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2f943d71, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3e57cd70, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@5bcea91b], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
16:41:35.691 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.691 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.734 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1} . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.0.RELEASE) 2019-03-02 16:41:36.379 INFO 18776 --- [ main] com.sharp.forward.JavaShiroTest : Starting JavaShiroTest on litan with PID 18776 (started by litan in D:\worksheet\shiro)
2019-03-02 16:41:36.382 INFO 18776 --- [ main] com.sharp.forward.JavaShiroTest : No active profile set, falling back to default profiles: default
2019-03-02 16:41:39.311 INFO 18776 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-03-02 16:41:39.904 INFO 18776 --- [ main] com.sharp.forward.JavaShiroTest : Started JavaShiroTest in 4.153 seconds (JVM running for 5.806)
2019-03-02 16:41:40.645 INFO 18776 --- [ main] a.s.s.m.AbstractValidatingSessionManager : Enabling session validation scheduler...
subject.isAuthenticated(): true
2019-03-02 16:41:41.163 INFO 18776 --- [ Thread-2] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
helloworld运行结果
参考https://www.cnblogs.com/fengan/p/5904445.html,重建project有时也可以解决
eclipse springboot运行helloworld错误: 找不到或无法加载主类 xxx.xxx.xxx的更多相关文章
- springboot项目上有个红叉,且ecplise没有自动编译项目,运行提示“错误: 找不到或无法加载主类”
近期在做springboot项目,发现springboot项目上有个红叉但找不到哪个类报错,ecplise没有把项目自动编译,运行还提示“错误: 找不到或无法加载主类”,进入工作空间“项目\targe ...
- Eclipse 无法编译,提示“错误: 找不到或无法加载主类”
jar包问题: 1.项目的Java Build Path中的Libraries中有个jar包的Source attachment指为了一个不可用的jar包, 解决办法是:将这个不可用的jar包remo ...
- zzw原创_cmd下带jar包运行提示 “错误: 找不到或无法加载主类 ”
在windows下编译java,由于是临时测试一下文件,不想改classpath,就在命令行中用 -cp 或classpath引入jar包,用javac编译成功,便使用java带-cp 或classp ...
- maven打包 运行出现 错误: 找不到或无法加载主类 jar
使用maven进行打包成jar包后 使用java -jar运行jar包 出现 错误: 找不到或无法加载主类 jar 主要是由于依赖没下载好,重新下载依赖 以及要在项目的pom.xml里面添加 < ...
- Myeclipse运行提示错误: 找不到或无法加载主类 test.test1 终极解决办法
前提是代码没有问题 简单粗暴的解决办法: 重启电脑 解决办法2: 1.在控制台中点开“Problems”,查看里面的错误.如果是多个项目,可以将其他项目暂时关闭. 根据错误进行处理. 2.把项目cle ...
- eclipse 执行main方法 错误: 找不到或无法加载主类
检查环境变量是否正确 JAVA_HOME JAVA的实际安装目录 CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\ ...
- 今天遇到一件开心事,在eclipse编写的代码在命令窗口中编译后无法运行,提示 “错误: 找不到或无法加载主类”
java中带package和不带package的编译运行方式是不同的. 首先来了解一下package的概念:简单定义为,package是一个为了方便管理组织java文件的目录结构,并防止不同java文 ...
- springboot错误: 找不到或无法加载主类
一:当在eclipse启动spring boot项目时出现问题: springboot错误: 找不到或无法加载主类 解决办法: 1,通过cmd命令行,进入项目目录进行,mvn clean instal ...
- mac 下 使用 java运行 class 文件 总是提示 “错误: 找不到或无法加载主类”的解决方法
发现问题 切换到mac平台后,突然想写点程序运行在mac下,想到mac自带java,会方便好多.不过在这过程中遇到了麻烦: 总是提示 “错误: 找不到或无法加载主类” 工程结构 查了好久,终于找到原型 ...
随机推荐
- python 可视化 pyecharts
github搜索pyecharts https://github.com/pyecharts/pyecharts echarts : https://www.echartsjs.com/zh/inde ...
- 附:Struts2-CRM,拦截器实现权限访问
拦截器代码: package mycrm.interceptor; import org.apache.struts2.ServletActionContext; import com.opensym ...
- git 删除分支和回退到以前某个提交版本
1.git 创建和删除分支: 创建:git branch 分支名字 本地删除:git branch -D 分支名字 远程删除:git push origin :分支名字 2.git 回退到以前提交的版 ...
- mybatis 查询标签
语法 参考:http://www.mybatis.org/mybatis-3/zh/dynamic-sql.html <![CDATA[内容]]>: 参考: http://blog.csd ...
- Checked exceptions: Java’s biggest mistake-检查型异常:Java最大的错误(翻译)
原文地址:http://literatejava.com/exceptions/checked-exceptions-javas-biggest-mistake/ 仅供参考,毕竟我四级都没过 Chec ...
- 建小程序 - 报Error: EPERM : operation not permitted, scandir mac下改变一个目录的访问权限
问题:用微信开发者工具,建一个小程序,报错(见图1): 建小程序 - 报Error: EPERM : operation not permitted, scandir 解决: 1.打开终端 2.cd ...
- R语言 which() 、 which.min() 、 which.max() 函数
函数 which() 可以用来找到满足条件的下标,如 x <- c(3, 4, 3, 5, 7, 5, 9) which(x > 5) 5 7 seq(along=x)[x > 5] ...
- 使用git下载一个项目
1.安装好git之后创建一个库repository,用来保存git项目 2.进入repository之后,右击之后,选中 git bash here菜单选项 3.弹出命令界面之后输入命令: git c ...
- 设计模式课程 设计模式精讲 21-2 观察者模式coding
1 代码演练 1.1 代码演练1(一对一观察) 1.2 代码演练2(一对多观察) 1.3 代码演练3(多对多观察) 1 代码演练 1.1 代码演练1(一对一观察) 需求: 木木网课程系统,教师后台提醒 ...
- Java程序员常用工具类库
有人说当你开始学习Java的时候,你就走上了一条不归路,在Java世界里,包罗万象,从J2SE,J2ME,J2EE三大平台,到J2EE中的13中核心技术,再到Java世界中万紫千红的Framework ...