亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Antlr4 在自己的 Maven 模塊中

Antlr4 在自己的 Maven 模塊中

慕容3067478 2023-07-28 16:09:22
當我構建使用 Antlr4 的 maven 模塊并查看 Jar 時,從 Antlr4 編譯生成的源位于根文件夾中。但是,當我想將 Jar 與生成的源作為依賴項包含在我的 Antlr4-impl 模塊中,而我想使用生成的類時,它們無法找到。我怎樣才能正確地將它們鏈接起來?我是否必須將生成的源移動到 maven src/main/java 部分?他們需要包裹嗎?如果是,我如何在maven插件中設置源包?這是 antlr 生成模塊中的我的 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">    <parent>        <artifactId>net-site-arti</artifactId>        <groupId>net.site.reverse</groupId>        <version>1.0-SNAPSHOT</version>        <relativePath>../pom.xml</relativePath>    </parent>    <modelVersion>4.0.0</modelVersion>    <artifactId>net-site-arti-antlr</artifactId>    <dependencies>        <dependency>            <groupId>org.antlr</groupId>            <artifactId>antlr4-runtime</artifactId>            <version>4.7.1</version>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.antlr</groupId>                <artifactId>antlr4-maven-plugin</artifactId>                <version>4.7.1</version>                <configuration>                    <outputDirectory>src/main/generated-sources</outputDirectory>                </configuration>                <executions>                    <execution>                        <goals>                            <goal>antlr4</goal>                        </goals>                    </execution>                </executions>            </plugin>
查看完整描述

1 回答

?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

不是一個完美的解決方案,而是一個解決方案:

不幸的是,ANTLR 不會在 Sourcefolder 中生成包,它只生成帶有包聲明的類文件。所以你必須在包中生成它們:

這是一個 pom 示例:

<plugin>

? ? ? ? ? ? ? ? <groupId>org.antlr</groupId>

? ? ? ? ? ? ? ? <artifactId>antlr4-maven-plugin</artifactId>

? ? ? ? ? ? ? ? <version>4.7.1</version>

? ? ? ? ? ? ? ? <configuration>

? ? ? ? ? ? ? ? ? ? <outputDirectory>src/main/java/net/site/antlr</outputDirectory>

? ? ? ? ? ? ? ? </configuration>

? ? ? ? ? ? ? ? <executions>

? ? ? ? ? ? ? ? ? ? <execution>

? ? ? ? ? ? ? ? ? ? ? ? <goals>

? ? ? ? ? ? ? ? ? ? ? ? ? ? <goal>antlr4</goal>

? ? ? ? ? ? ? ? ? ? ? ? </goals>

? ? ? ? ? ? ? ? ? ? </execution>

? ? ? ? ? ? ? ? </executions>

? ? ? ? ? ? </plugin>

如果將其添加到 g 文件中:


@header {

? ? package net.site.antlr;

}

但使用此解決方案,您無法在不同的包中生成不同的語法。


查看完整回答
反對 回復 2023-07-28
  • 1 回答
  • 0 關注
  • 232 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號