idea 找不到或无法加载主类

1.现象

在idea中运行main方法是提示 "找不到或者无法加载主类xxxx"。试了网上各种教程,均无效

2.现状

2.1 项目简介

项目中有多个模块,均属于一个父项目。模块中scala和java进行混用

2.2 jdk&scala配置

jdk版本为jdk1.8;scala为2.12版本

2.3 maven配置

maven中打包插件如下

<build>
        <plugins>
            <!-- 依赖 插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <configuration>
                    <minimizeJar>false</minimizeJar>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.protobuf</pattern>
                                    <shadedPattern>com.google.shaded.protobuf</shadedPattern>
                                </relocation>
                            </relocations>
                            <artifactSet>
                                <excludes>
                                    <exclude>org.scala-lang:*</exclude>
                                </excludes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- scala 插件 -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>4.4.0</version>
                <configuration>
                    <recompileMode>incremental</recompileMode>
                    <addScalacArgs>-target:jvm-1.8</addScalacArgs>
                    <compileOrder>JavaThenScala</compileOrder>  <!-- otherwise lombok won't work -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- java 插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <!-- Add protobuf-maven-plugin and provide ScalaPB as a code generation plugin -->
            <!-- protoc 插件 -->
            <plugin>
                <groupId>com.github.os72</groupId>
                <artifactId>protoc-jar-maven-plugin</artifactId>
                <version>3.11.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <protocArtifact>com.google.protobuf:protoc:2.5.0</protocArtifact>
                    <protocVersion>2.5.0</protocVersion>
                    <inputDirectories>
                        <include>src/main/protobuf</include>
                    </inputDirectories>
                    <includeMavenTypes>transitive</includeMavenTypes>
                    <outputTargets>
                        <outputTarget>
                            <type>scalapb</type>
                            <!--<outputOptions>grpc</outputOptions> &lt;!&ndash; more scalapb options can be added here &ndash;&gt;-->
                            <!--suppress UnresolvedMavenProperty -->
                            <pluginArtifact>com.thesamet.scalapb:protoc-gen-scala:0.9.8:sh:unix</pluginArtifact>
                            <outputDirectory>src/main/scala</outputDirectory>
                        </outputTarget>
                    </outputTargets>
                </configuration>
            </plugin>

            <!--  跳过测试用例  -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>

3.解决方法

笔者一步步验证,发现jdk版本、scala版本、maven等配置均没有问题。

后来删除.idea文件夹下内容,重启idea 即可,也算是一个大招了,😂

也算是比较坑了,一个月会遇到一两次 无法加载主类的问题,此处作记录

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值