用于MATLAB编译器项目的Maven pom.xml



我有一个Tomcat servlet项目,它需要mcc生成的MATLAB jar。我已经实现了一个生成jar的mojo插件(mcc-maven插件(。它只需从pom中获取规范,并创建以下形式的MATLAB命令:cd'/home/jeffemandel/webpropofolmm/matlab/src/main/matlab';mcc-W'java:webpropofol_java,loadServlet'-d'/home/jeffemandel/webpropofolmm/matlab/target'class{loadServlet:loadServlet.m}class{locServlet:locServlet.m}class{testStruct:testStruct.m}

这将生成文件/home/jeffemandel/webpropofolmm/matlab/target/webpropofol_java.jar请注意,mcc必须存在目标才能工作。

我在我的主项目中需要这个文件,但每次我对UI(它有少量的Java和大量的HTML、css和javascript(进行小调整时都要生成jar,这是一项资源密集型工作。我的困惑点是如何生成一个不依赖于任何Java代码的jar。这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.jeffmandel.webpropofol</groupId>
<artifactId>optimaltiva</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javabuilder</groupId>
<artifactId>javabuilder</artifactId>
<version>9.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jeffmandel</groupId>
<artifactId>mcc-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>mcc</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<packageName>webpropofol_java</packageName>
<className>loadServlet</className>
<classes>
<loadServlet>loadServlet.m</loadServlet>
<locServlet>locServlet.m</locServlet>
<testStruct>testStruct.m</testStruct>
</classes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<groupId>org.jeffmandel.webpropofol</groupId>
<artifactId>optimaltiva</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${project.build.directory}/webpropofol_java.jar</file>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

当我运行mvn-compile时,我得到的是:

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------< org.jeffmandel.webpropofol:optimaltiva >---------------
[INFO] Building optimaltiva 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ optimaltiva ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jeffemandel/webpropofolmm/matlab/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ optimaltiva ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-antrun-plugin:1.4:run (default) @ optimaltiva ---
project.artifactId
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] 
[INFO] --- mcc-maven-plugin:0.0.1-SNAPSHOT:mcc (default) @ optimaltiva ---
[INFO] cd '/home/jeffemandel/webpropofolmm/matlab/src/main/matlab';mcc -W 'java:webpropofol_java,loadServlet' -d '/home/jeffemandel/webpropofolmm/matlab/target' class{loadServlet:loadServlet.m}  class{locServlet:locServlet.m}  class{testStruct:testStruct.m} 
[INFO] Loading source files for package webpropofol_java...
Constructing Javadoc information...
Standard Doclet version 1.8.0_221
Building tree for all the packages and classes...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/loadServlet.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/loadServletRemote.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/locServlet.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/locServletRemote.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/testStruct.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/testStructRemote.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/Webpropofol_javaMCRFactory.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/package-frame.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/package-summary.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/webpropofol_java/package-tree.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/constant-values.html...
Building index for all the packages and classes...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/overview-tree.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/index-all.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/deprecated-list.html...
Building index for all classes...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/allclasses-frame.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/allclasses-noframe.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/index.html...
Generating /home/jeffemandel/webpropofolmm/matlab/target/doc/html/help-doc.html...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  36.215 s
[INFO] Finished at: 2020-12-12T22:26:54-05:00
[INFO] -----

问题是,每次我运行mvn-compile时,它都会生成jar,而不是看到源文件没有更改,所以不要重新生成jar。我的最终目标是拥有一个包含matlab和servlet的项目。

我做了更多的阅读,发现mojo插件有责任确定是否需要重新编译。MATLAB需要重建整个jar,即使只有一个文件发生了更改,所以我在我的mojo插件中添加了以下代码:

import org.apache.commons.io.filefilter.AgeFileFilter;
import java.io.FileFilter;
File myJar = new File(outputDirectory + File.separator + packageName + ".jar");
AgeFileFilter myFilter = new AgeFileFilter(myJar, false);
File source = new File(sourceDirectory);
File[] files = source.listFiles((FileFilter) myFilter);
if (files.length==0) {
getLog().info("Project up to date");
} else {
...
}

这就奏效了。

最新更新