2021SC@SDUSC
openmeetings提供视频会议、即时消息、白板、协作文档编辑和其他组件工具。以下是openmeetings4.0.7的src源码,打开之后有十个主要文件夹,分别是openmeetings-core、 openmeetings-db、openmeetings-flash、openmeetings-install、openmeetings-screenshare、openmeetings-server、openmeetings-service、openmeetings-util、openmeetings-web、openmeetings-webservice,然后还有一些.md文件提供了一些该项目的信息可供读者阅读。该项目的整个目录结构十分清晰,每个文件会实现其相关功能,是由maven项目管理工具管理的项目,maven对项目进行构建和依赖管理。
附:POM( Project Object Model,项目对象模型 )是Maven工程的基本工作单元,是一个XML文件,包含了项目的基本信息,用于描述项目如何构建,声明项目依赖,等等。执行任务或目标时,Maven会在当前目录中查找POM。它读取POM,获取所需的配置信息,然后执行目标。
主要任务
我负责的部分包括openmeetings-screenshare和openmeetings-util两个模块,我选择首先分析openmeetings-screenshare模块。本文主要对模块的结构进行梳理,开始源码的分析工作。
而打开其中任意一个文件夹,例如打开openmeetings-screenshare:其同样是一个标准的maven目录结构。pom.xml则是maven项目的核心配置文件,是maven项目必须具备的文件。Src目录包含了main和site目录,其中main是存放项目的java文件及资源,site目录中保存了项目将要生成的各html文件等等。
所有 POM 文件都需要 project 元素和三个必需字段:groupId,artifactId,version。在根目录下的pom.xml文件中(openmeetings-parent)
project | 工程的根标签。 |
modelVersion | 模型版本需要设置为 4.0。 |
groupId | 这是工程组的标识。它在一个组织或者项目中通常是唯一的。例如,一个银行组织 com.companyname.project-group 拥有所有的和银行相关的项目。 |
artifactId | 这是工程的标识。它通常是工程的名称。例如,消费者银行。groupId 和 artifactId 一起定义了 artifact 在仓库中的位置。 |
version | 这是工程的版本号。在 artifact 的仓库中,它用来区分不同的版本。例如: com.company.bank:consumer-banking:1.0 com.company.bank:consumer-banking:1.1 |
(来自菜鸟驿站Maven POM | 菜鸟教程 (runoob.com))
如下图根目录的pom.xml文件的信息
dependencies和dependency依赖:
Maven的一个重要作用就是管理jar包,为了一个项目可以构建或运行,项目中不可避免要依赖许多其他jar包。在Maven中,这些jar就被称为依赖,使用标签dependency来配置。而这种依赖的配置正是通过坐标来定位的,maven把所有的jar包都视为项目存在了。
如:根目录的pom.xml文件描述了项目所需的子项目的默认依赖信息,这些依赖组成了项目构成中的一个个环节。这部分的依赖信息不会立即被解析,而是当子项目声明一个依赖,如果除了groupId和artifactId以外的一些信息没有描述,则通过group ID和artifact ID 匹配到这里的依赖,并使用这里的依赖信息。
properties配置属性:properties是用来定义一些配置属性的,例如project.build.sourceEncoding(项目构建源码编码方式),可以设置为UTF-8,防止中文乱码
build构建:build表示与构建相关的配置
parent与modules:也有类似Java的继承机制,用parent声明要继承的父工程的pom配置。在其中使用modules聚合的其他模块,这样通过本模块就可以一键自动识别模块间的依赖关系来构建所有模块。
openmeetings中一个重要的功能便是在视频会议中进行屏幕共享的功能。可以选择区域进行共享,随时结束共享,屏幕共享的不同质量步骤,在集成的拖放文件资源管理器中观看和组织录制。
首先看openmeetings-screenshare目录下的pom.xml文件:结构如下
附上源码:
<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>
<parent>
<groupId>org.apache.openmeetings</groupId>
<artifactId>openmeetings-parent</artifactId>
<version>4.0.7</version>
<relativePath>..</relativePath>
</parent>
<artifactId>openmeetings-screenshare</artifactId>
<packaging>jar</packaging>
<name>Openmeetings Screen Sharing applet</name>
<description>Module to build OpenMeetings web application to grab a screen and send it to a Server</description>
<properties>
<keystore.location>${project.build.directory}/screensharing_sign.keystore</keystore.location>
<key.password>secret</key.password>
<keystore.password>secret</keystore.password>
<keystore.type>pkcs12</keystore.type>
<key.alias>screen</key.alias>
<site.basedir>${project.parent.basedir}</site.basedir>
<jnlp.out.dir>${project.build.directory}/jnlp</jnlp.out.dir>
</properties>
<dependencies>
<dependency>
<groupId>org.red5</groupId>
<artifactId>red5-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>${mina.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>create-template</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/jnlp/templates</directory>
<includes>
<include>*.jnlp</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-icons</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jnlp.out.dir}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/jnlp/resources</directory>
<includes>
<include>*.png</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<configuration>
<target>
<copy file="${project.build.directory}/template.jnlp" tofile="${jnlp.out.dir}/APPLICATION.jnlp" overwrite="true" force="true" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<executions>
<execution>
<goals><goal>generateKeyPair</goal></goals>
<phase>generate-resources</phase>
<configuration>
<keystore>${keystore.location}</keystore>
<storepass>${keystore.password}</storepass>
<keypass>${key.password}</keypass>
<alias>${key.alias}</alias>
<dname>cn=Sebastian Wagner, ou=technolog, o=openmeetings.apache.org, c=DE</dname>
<ext></ext>
<validity>365</validity>
<keyalg>RSA</keyalg>
<keysize>4096</keysize>
<storetype>${keystore.type}</storetype>
<skip>${jarsigner.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-screen-sharing</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<outputDirectory>${jnlp.out.dir}</outputDirectory>
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<mainClass>org.apache.openmeetings.screenshare.Core</mainClass>
</manifest>
<manifestEntries>
<Application-Name>${project.name}</Application-Name>
<Built-By>OpenMeetings - https://openmeetings.apache.org</Built-By>
<Built-On>${maven.build.timestamp}</Built-On>
<Git-Revision>${buildNumber}</Git-Revision>
<Product-Version>${project.version}</Product-Version>
<Permissions>all-permissions</Permissions>
<Trusted-Only>true</Trusted-Only>
<Codebase>*</Codebase>
<Crypto-Strength>unlimited</Crypto-Strength>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-bcprov</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${jnlp.out.dir}</outputDirectory>
<includeArtifactIds>bcprov-jdk15on</includeArtifactIds>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeTransitive>false</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<executions>
<execution>
<id>sign-applet</id>
<phase>package</phase>
<goals><goal>sign</goal></goals>
<configuration>
<archiveDirectory>${jnlp.out.dir}</archiveDirectory>
<keystore>${keystore.location}</keystore>
<keypass>${key.password}</keypass>
<storepass>${keystore.password}</storepass>
<storetype>${keystore.type}</storetype>
<alias>${key.alias}</alias>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
最开始的project标签是基础的内容,接下来是parent标签是继承,通过groupId、artifactId、version表明了父工程的位置,即openmeetings项目,便可以直接引用父工程的依赖了。上文有提到此相关内容。然后是packaging标签规定打包类型为jar。Properyies标签内可以自定义maven属性,dependencies标签内完成配置依赖,每个dependency标签会指明该依赖对应的坐标。然后是build标签表述了与构建相关的配置,描述了项目的编译和打包,通过plugin配置来完成。
总结:
分析了openmeetings-screenshare的目录结构以及对pom.xml进行了初步分析,接下来逐步展开对src目录下的文件的分析。