项目重构00 Java maven项目下,集成Scala混合开发

作为补充我找了个Scala项目,但这不是我重构的了,旨在说明问题,没什么区别。

pom文件,这个是我的项目的pom,其他依赖可以不用写。

github 项目地址 https://github.com/jxnu-liguobin/SpringBoot-Base-System

注意Scala版本号

注意Scala版本号

注意Scala版本号

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>cn.jxnu.edu</groupId>
	<artifactId>base</artifactId>
	<version>1.0-SNAPSHOT</version>

	<!-- Inherit defaults from Spring Boot -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.9.RELEASE</version>
	</parent>

	<properties>
		<!--跳过测试 -->
		<skipTests>true</skipTests>
		<shiro.version>1.2.4</shiro.version>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>

		<!-- scala 这里2个版本的号必须对应,否则编译失败,自己仔细看仓库的号 -->
		<dependency>
			<groupId>org.scala-lang</groupId>
			<artifactId>scala-library</artifactId>
		<version>2.11.8</version>
		</dependency>
		<dependency>
			<groupId>com.typesafe.scala-logging</groupId>
			<artifactId>scala-logging-slf4j_2.11</artifactId>
			<version>2.1.2</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- SpringBoot热部署依赖 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency>
		<!-- 添加freemarker资源 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-freemarker</artifactId>
		</dependency>
		<!--添加spring boot 配置处理器 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-configuration-processor</artifactId>
			<optional>true</optional>
		</dependency>
		<!-- 添加SpringData JPA -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<!-- 添加SpringBoot缓存依赖 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-cache</artifactId>
		</dependency>
		<!-- 单元测试 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<!--添加数据库连接池 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.15</version>
		</dependency>
		<!-- Ehcache -->
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache</artifactId>
		</dependency>
		<!--添加Shiro -->
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-core</artifactId>
			<version>${shiro.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-spring</artifactId>
			<version>${shiro.version}</version>
		</dependency>
		<!-- Shiro 标签 -->
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-web</artifactId>
			<version>${shiro.version}</version>
		</dependency>
		<!--添加数据库驱动 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!--添加工具 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>3.3.2</version>
		</dependency>
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.46</version>
		</dependency>
		<!-- 添加日期/时间库 -->
		<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
		</dependency>

		<dependency>
			<groupId>org.jadira.usertype</groupId>
			<artifactId>usertype.core</artifactId>
			<version>5.0.0.GA</version>
		</dependency>

		<dependency>
			<groupId>org.jadira.usertype</groupId>
			<artifactId>usertype.spi</artifactId>
			<version>5.0.0.GA</version>
		</dependency>
		<!-- 添加aop支持 CGLIB需要配置spring.aop.proxy-target-class=true,不然默认使用的是标准Java的实现。 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-aop</artifactId>
		</dependency>
		<!-- 添加redis缓存支持 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-ehcache</artifactId>
			<version>1.2.4</version>
		</dependency>
		<!-- 减少冗余 -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
		</dependency>
	</dependencies>

	<build>
<!-- 指定Scala的目录,我采用maven默认目录,你也可以指定为src/main/scala,但是你的源文件也应该是这个-->
		<sourceDirectory>src/main/java</sourceDirectory>
		<testSourceDirectory>src/test/java</testSourceDirectory>
		<plugins>
			<plugin><!-- Scala编译插件 -->
				<groupId>org.scala-tools</groupId>
				<artifactId>maven-scala-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>compile</goal>
							<goal>testCompile</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<recompileMode>incremental</recompileMode>
					<scalaVersion>2.11.8</scalaVersion>
					<launchers><!-- 启动类,是java或者scala都可以,全路径名!!!! -->
						<launcher>
							<id>app</id>
							<mainClass>cn.edu.jxnu.base.Application</mainClass>
							<args>
								<arg>-deprecation</arg>
							</args><!-- 启动虚拟机参数-->
							<jvmArgs>
								<jvmArg>-Xms64m</jvmArg>
								<jvmArg>-Xmx1024m</jvmArg>
							</jvmArgs>
						</launcher>
					</launchers>
				</configuration>
			</plugin>
			<plugin><!-- maven自带编译插件,编译java-->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>

			<!-- 在Goals中输入:org.apache.maven.plugins:maven-jar-plugin:2.4:jar org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<mainClass>cn.edu.jxnu.base.Application</mainClass>
					<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
				</configuration>
				<dependencies>
					<!-- spring热部署 -->
					<dependency>
						<groupId>org.springframework</groupId>
						<artifactId>springloaded</artifactId>
						<version>1.2.5.RELEASE</version>
					</dependency>
				</dependencies>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

这里有几点注意是,如果使用Lombok插件,自动编译生产get/set方法,在写Scala代码的时候,可能是找不到set/get,此时需要重新编译Scala【我是随便找个scala项目演示】

选择restart Presentation complier 即可


最好设置一下eclipse编译顺序,先编译Java,保证scala编译之前已经有Java的set/get方法,这样即使有打叉,但是运行是OK的。


增加maven配置后还是有Scala代码有大红色的叉叉,就试着给项目添加Scala本地库依赖


IDEA 类似。只是菜单位置不同。

仅供参考。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值