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> <!– more scalapb options can be added here –>-->
<!--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 即可,也算是一个大招了,😂
也算是比较坑了,一个月会遇到一两次 无法加载主类的问题,此处作记录
|