我是Maven的新手。我有一个项目,其中包含一个由语法分析器生成器SableCC读取的语法定义文件。 SableCC读取语法文件并生成Java源代码,该Java源代码一旦编译,便会创建解析器。该解析器供我项目的其余部分使用。
[我认为我的问题不是SableCC问题,因为我已经看到了类似的使用Antlr(与SableCC相当的解析器生成器)的POM.XML文件,而该POM.XML的<plugin>
部分看起来几乎与我的POM.XML文件中的<plugin>
部分相同。
这是我的项目的文件结构,标识出SableCC使用的那些部分:
这是我完整的POM.XML文件,根据到目前为止我看到的插件示例(尤其是SableCC的插件示例),我将其拼凑在一起:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mbm</groupId>
<artifactId>properties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Properties</name>
<description>Define and process program arguments</description>
<dependencies>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sablecc-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
我的问题是SableCC插件如何知道输入文件在哪里以及生成的输出Java源文件的4类(分析,词法分析器,节点和解析器)应该在哪里?我怀疑我需要在我的POM文件中添加更多的Maven“资料”,但我不知道该怎么办。
您可以在此处查看插件配置:https://github.com/tychobrailleur/sablecc-maven-plugin
更具体地说:
sourceDirectory:包含语法文件的目录。默认情况下,$ {basedir} / src / main / sablecc
outputDirectory:包含生成的源的目录。默认情况下,$ {project.build.directory} / generated-sources / sablecc
您还可以提取JAR并在plugin.xml文件中查看这些配置:
<configuration>
<outputDirectory implementation="java.lang.String">${project.build.directory}/generated-sources/sablecc</outputDirectory>
<timestampDirectory implementation="java.lang.String">${basedir}/target</timestampDirectory>
<sourceDirectory implementation="java.lang.String">${basedir}/src/main/sablecc</sourceDirectory>
<project implementation="org.apache.maven.project.MavenProject">${project}</project>
<staleMillis implementation="int" default-value="0">${lastModGranularityMs}</staleMillis>
</configuration>