后期处理 Antlr Maven 目标

发布于 2025-01-18 06:17:34 字数 727 浏览 3 评论 0原文

我正在使用 Maven 运行 Antlr。 Antlr 从 .g 文件生成 .java 文件,我需要后期处理生成的 java 文件(对其进行一些更改)。我该怎么做呢?

<plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr3-maven-plugin</artifactId>
            <version>3.5.2</version>
            <configuration>
                <outputDirectory>src/main/java</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>antlr</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I'm running antlr with maven. Antlr generates .java file from .g file and I need to post process generated java file (do some changes in it). How can I do it?

<plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr3-maven-plugin</artifactId>
            <version>3.5.2</version>
            <configuration>
                <outputDirectory>src/main/java</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>antlr</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两人的回忆 2025-01-25 06:17:34

最后,我找到了解决方案。您必须使用Maven-Antrun-Plugin,它可以执行Java代码。
另一个问题是,在流程源阶段还没有编译类(您需要在编译之前运行)。因此,在执行Java类之前,您需要像我一样对其进行编译或做 - 存储已经编译的类并将其复制到目标类。

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy file="path\to\LogicsParserPostProcess.class"
                                      tofile="path\to\target\classes\LogicsParserPostProcess.class" />
                                <java classname="LogicsParserPostProcess" failonerror="true">
                                    <classpath refid="maven.compile.classpath"/>
                                </java>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Finally I've found a solution. You have to use maven-antrun-plugin, it can execute java code.
Another problem was that there were no compiled classes yet in the process-sources phase (you need to run it before compile). So before executing the java class, you need to compile it or do as I did - store the already compiled class and copy it to target classes.

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy file="path\to\LogicsParserPostProcess.class"
                                      tofile="path\to\target\classes\LogicsParserPostProcess.class" />
                                <java classname="LogicsParserPostProcess" failonerror="true">
                                    <classpath refid="maven.compile.classpath"/>
                                </java>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文