liferay eclipse使用maven创建开发theme主题皮肤项目

java | 2019-09-13 10:02:39

iferay其实很简单,不会的可能要绕很大圈,分享一下,先从环境搭建开始直到发布liferay theme主题成功!

1.eclipse安装liferay开发插件
这个很简单,首先你安装了jdk,然后下载好了eclipse,安装了maven插件,这些做java开发必备的基础就不赘述了。好开始安装liferay插件:eclipse-菜单栏-help-marketplace-搜索 liferay-安装第一个。
等一会就安装成功了会让你重启eclipse。
然后工具栏就会出现liferay的工具插件,如图:

1.jpg


2.下载liferay portal

不想多说去官网下载就可以www.liferay.com也可以去sourceforge中下载:https://sourceforge.net/projects/lportal/files/Liferay%20Portal/

下载的其实是一个包含tomcat的web服务软件,可以直接启动里面的tomcat运行liferay。我下载了:liferay-portal-tomcat-6.2-ce-ga6-20160112152609836.zip

3.eclipse中启动liferay
servers右键-new-列表中中选liferay-下拉框中选liferay(没有就点add-弹出再点add-选liferay-点击next-选择你上一步下载的liferay-不用选到liferay中的tomcat)-finish。

2.jpg

和新建一个tomcat一样很简单,不多说。
选中servers中建好的liferay点击启动,启动完了会自动打开浏览器开始初始设置。等吧,要等很久。

4.新建liferay theme主题项目
eclipse装好插件后就可以直接点工具栏中的liferay新建liferay项目。前提你的maven已经配好了,装maven插件了不配也可以,用默认的设置嘛。
工具栏-liferay选择new liferay plugin project

3.jpg

输入名称-选择maven项目-选择项目类型theme-finished。
新建的项目很多文件都是空的,而且有错误。
改pom:

<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.csot.plugins</groupId>
        <artifactId>csot-gray-theme</artifactId>
        <packaging>war</packaging>
        <name>csot-gray-theme Theme</name>
        <version>1.0.0-SNAPSHOT</version>
        <properties>
                <liferay.theme.parent>_styled</liferay.theme.parent>
                <liferay.theme.type>ftl</liferay.theme.type>
                <liferay.version>6.2.5</liferay.version>
                <liferay.maven.plugin.version>6.2.5</liferay.maven.plugin.version>
                <liferay.auto.deploy.dir>D:\workspace\liferay6\liferay-portal-6.2-ce-ga6\deploy</liferay.auto.deploy.dir>
                
        </properties>
        <build>
                <plugins>
                        <plugin>
                                <groupId>com.liferay.maven.plugins</groupId>
                                <artifactId>liferay-maven-plugin</artifactId>
                                <version>${liferay.maven.plugin.version}</version>
                                <executions>
                                        <execution>
                                                <phase>generate-sources</phase>
                                                <goals>
                                                        <goal>theme-merge</goal>
                                                        <goal>build-css</goal>
                                                        <goal>build-thumbnail</goal>
                                                </goals>
                                        </execution>
                                </executions>
                                <configuration>
                                        <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                                        <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
                                        <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
                                        <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
                                        <liferayVersion>${liferay.version}</liferayVersion>
                                        <parentTheme>${liferay.theme.parent}</parentTheme>
                                        <pluginType>theme</pluginType>
                                        <themeType>${liferay.theme.type}</themeType>
                                        
                                </configuration>
                        </plugin>
                        <plugin>
                                <artifactId>maven-resources-plugin</artifactId>
                                <version>2.5</version>
                                <configuration>
                                        <encoding>UTF-8</encoding>
                                </configuration>
                        </plugin>
                </plugins>
        </build>
        <dependencies>
                <dependency>
                        <groupId>com.liferay.portal</groupId>
                        <artifactId>portal-service</artifactId>
                        <version>${liferay.version}</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>com.liferay.portal</groupId>
                        <artifactId>util-bridges</artifactId>
                        <version>${liferay.version}</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>com.liferay.portal</groupId>
                        <artifactId>util-taglib</artifactId>
                        <version>${liferay.version}</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>com.liferay.portal</groupId>
                        <artifactId>util-java</artifactId>
                        <version>${liferay.version}</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>javax.portlet</groupId>
                        <artifactId>portlet-api</artifactId>
                        <version>2.0</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>servlet-api</artifactId>
                        <version>2.4</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>javax.servlet.jsp</groupId>
                        <artifactId>jsp-api</artifactId>
                        <version>2.0</version>
                        <scope>provided</scope>
                </dependency>
        </dependencies>
</project>


主要加了proterties。加上版本和自己下载的liferay.

<properties>
                <liferay.theme.parent>_styled</liferay.theme.parent>
                <liferay.theme.type>ftl</liferay.theme.type>
                <liferay.version>6.2.5</liferay.version>
                <liferay.maven.plugin.version>6.2.5</liferay.maven.plugin.version>
                <liferay.auto.deploy.dir>D:\workspace\liferay6\liferay-portal-6.2-ce-ga6\deploy</liferay.auto.deploy.dir>
                
        </properties>


右键点击项目 run as maven install。
等吧要很久。

等maven运行完,查看项目。多了好多文件。

5.jpg


target里面的css、image、js、templates是默认的。
你要自己开发主题皮肤只要在webapp中新建相应的文件覆盖即可。
项目建完了你可以开发自己的主题了,慢慢爬坑吧。
css就从custom.css覆盖在里面写自己的代码就可以了。
js就覆盖main.js
templets随便你覆盖。

5.部署liferay主题
liferay支持热部署的。
方式1.把target中的war包复制到下载好的liferay中的deploy中就可以自动发布主题项目,当然protlet也一样。
还记得在pom.xm文件中配置的liferay.auto.deploy.dir

方式2.既然配置了,maven也可以直接打包到liferay server中啊

右键项目-liferay-maven-deploy

6.jpg


看控制台出现主题部署成功1 theme for user之类的,就可以刷新页面看你自己写的主题了(控制台不是自动切换的就自己切换看看,别只看到maven的信息);









登录后即可回复 登录 | 注册
    
关注编程学问公众号