北京网站制作合肥,美食网页设计模板中文,20平米的办公室怎样装修,惠州市住房和城乡建设厅网站文章目录 项目结构Pom完整文件编译查看 实际开发用有时候引用自己写的一些java工具类#xff0c;但是整个项目是scala开发的spark程序#xff0c;在项目打包时需要考虑到java和scala混合在一起编译。 今天看到之前很久之前写的一些打包编译文章#xff0c;发现很多地方不太对… 文章目录 项目结构Pom完整文件编译查看 实际开发用有时候引用自己写的一些java工具类但是整个项目是scala开发的spark程序在项目打包时需要考虑到java和scala混合在一起编译。 今天看到之前很久之前写的一些打包编译文章发现很多地方不太对于是重新整理更新如下。 项目结构
我们的项目结构可能如下图既包含java的程序也包含scala的程序。或者在scala的包中也包含了java程序。 实际开发中我们可以不写src/main/java这个包将java和scala程序全部放到src/main/scala中。
Pom完整文件
这是一个spark程序的完整的pom文件。
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.king/groupIdartifactIdggtool/artifactIdversion1.0-SNAPSHOT/versionpropertiesjava.version1.8/java.versionscala.version2.12.15/scala.versionspark.version3.3.0/spark.version/propertiesdependenciesdependencygroupIdorg.apache.spark/groupIdartifactIdspark-core_2.12/artifactIdversion3.3.0/version/dependencydependencygroupIdorg.apache.spark/groupIdartifactIdspark-sql_2.12/artifactIdversion3.3.0/version/dependencydependencygroupIdorg.scala-lang/groupIdartifactIdscala-library/artifactIdversion2.12.15/version/dependency/dependenciesbuildresourcesresourcedirectory${project.basedir}/src/main/resources/directory/resource/resourcesplugins!--解决java和scala混合编译出错--plugingroupIdnet.alchim31.maven/groupIdartifactIdscala-maven-plugin/artifactIdversion3.3.1/versionexecutionsexecutionidscala-compile-first/idphaseprocess-resources/phasegoalsgoaladd-source/goalgoalcompile/goal/goals/executionexecutionphasecompile/phasegoalsgoalcompile/goalgoaltestCompile/goal/goals/execution/executionsconfigurationscalaVersion${scala.version}/scalaVersionargsarg-target:jvm-1.8/arg/args/configuration/plugin!-- java compile--plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdversion3.1/versionconfigurationsource${java.version}/sourcetarget${java.version}/targetcompilerArgument-Xlint:unchecked/compilerArgument/configuration/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-shade-plugin/artifactIdversion3.2.4/versionexecutionsexecutionphasepackage/phasegoalsgoalshade/goal/goalsconfigurationcreateDependencyReducedPomfalse/createDependencyReducedPomfiltersfilterartifact*:*/artifactexcludesexcludeMETA-INF/*.SF/excludeexcludeMETA-INF/*.DSA/excludeexcludeMETA-INF/*.RSA/exclude/excludes/filter/filters/configuration/execution/executions/plugin/plugins/build
/projectscala-maven-plugin 用来打包scala程序 maven-compiler-plugin 用来打包java程序。
编译
这样在idea的右边工具栏中直接点击package即可完成打包。 在target的目录中完整的包如下。
查看
用压缩软件打开生成的jar包可以看到java和scala的文件都编译在一起了。