在liferay 7中如何删除service builder已经生成的数据库table

在Liferay 7中,加了数据库保护机制,你改了service.xml的结构后,重新运行service builder,并不会帮你生成新的数据库表。然后你发现你在数据库中自己手动删除了表后,重新部署项目到liferay portal上去并不会重新生成你想要的表。下面提供三种方法来解决这个问题:

1. 官方方法:db-support-gradle-plugin 用官方提供的gradle插件进行清除

 1.1 用liferay IDE建一个gradle类型的service builder项目

  1.2 右键项目运行service builder

   1.3 部署到liferay portal上(在这里我连的是mysql数据库,用的是portal-ext.properties进行配置的,前面的文章有写到怎么配)

    1.4 打开数据库,你会看到你建的表Foo_foo

     1.5 我建的项目名是sb,在sb/gradle.build中添加classpath group: "com.liferay", name: "com.liferay.gradle.plugins.db.support",           version: "1.0.2"

buildscript {
	dependencies {
		classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "3.1.3"
		classpath group: "com.liferay", name: "com.liferay.gradle.plugins.db.support", version: "1.0.2"
	}

	repositories {
		mavenLocal()

		maven {
			url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
		}
	}
}

subprojects {
	apply plugin: "com.liferay.plugin"

	repositories {
		mavenLocal()

		maven {
			url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
		}
	}
}

  1.6 在sb-service/build.gradle中添加dependencies dbSupport group: "mysql", name: "mysql-connector-java", version: "5.1.23"

             apply plugin: "com.liferay.portal.tools.db.support"

    配置cleanServiceBuilder的参数propertiesFile

    

apply plugin: "com.liferay.portal.tools.service.builder"
apply plugin: "com.liferay.portal.tools.db.support"

dependencies {
	compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
	compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
	compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
	compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"
	compileOnly project(":sb-api")
	dbSupport group: "mysql", name: "mysql-connector-java", version: "5.1.23"
}

buildService {
	apiDir = "../sb-api/src/main/java"
}

/*replace the properties file location with your own*/
cleanServiceBuilder { 
	propertiesFile = "F:/liferay-bundle/liferay-ce-portal-tomcat-7.0-ga3/liferay-ce-portal-7.0-ga3/portal-ext.properties"
}

group = "sb"

  1.7 刷新Gradle项目,打开gradle tasks可以看到cleanServiceBuilder任务,点击运行即可

1.8 运行成功后打开数据库,你发现你生成的表被删除了。然后重新部署项目,新的表就生成了

show u the code 

 

2. 简单粗暴也是最简单的方法,直接删除这个Liferay生成的数据库,下次重启的时候会重新生成

 

3. service component方法

 

posted @ 2017-06-21 17:24  Hibou  阅读(776)  评论(0编辑  收藏  举报