Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Antlr4在自己的Maven模块中_Java_Maven_Pom.xml_Antlr4 - Fatal编程技术网

Java Antlr4在自己的Maven模块中

Java Antlr4在自己的Maven模块中,java,maven,pom.xml,antlr4,Java,Maven,Pom.xml,Antlr4,当我构建使用Antlr4的maven模块并查看Jar时,从Antlr4编译生成的源代码位于根文件夹中。 但是,当我想在Antlr4 impl模块中包含Jar和生成的源代码作为依赖项时,我想在其中使用生成的类,但找不到它们。 我怎样才能把它们正确地连接起来?我是否必须将生成的源代码移动到maven src/main/java部分?他们需要一个包裹吗?如果是,如何设置maven插件中源代码的包 以下是我的pom.xml表单,用于antlr生成模块: <?xml version="1.0" en

当我构建使用Antlr4的maven模块并查看Jar时,从Antlr4编译生成的源代码位于根文件夹中。 但是,当我想在Antlr4 impl模块中包含Jar和生成的源代码作为依赖项时,我想在其中使用生成的类,但找不到它们。 我怎样才能把它们正确地连接起来?我是否必须将生成的源代码移动到maven src/main/java部分?他们需要一个包裹吗?如果是,如何设置maven插件中源代码的包

以下是我的pom.xml表单,用于antlr生成模块:

<?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>
             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/generated-sources</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

网站艺术
net.site.reverse
1.0-快照
../pom.xml
4.0.0
网站arti antlr
org.antlr
antlr4运行时
4.7.1
org.antlr
antlr4 maven插件
4.7.1
src/主/生成源
antlr4
org.codehaus.mojo
构建助手maven插件
1.7
添加源
生成源
添加源
src/主/生成源
下面是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-impl</artifactId>

    <dependencies>
        <dependency>
            <groupId>net.site.reverse</groupId>
            <artifactId>net-site-arti-antlr</artifactId>
            <version>${project.version}</version>
        </dependency>

            <dependency>
                <groupId>org.antlr</groupId>
                <artifactId>antlr4-runtime</artifactId>
                <version>4.7.1</version>
            </dependency>

    </dependencies>
</project>

网站艺术
net.site.reverse
1.0-快照
../pom.xml
4.0.0
网络站点arti antlr impl
net.site.reverse
网站arti antlr
${project.version}
org.antlr
antlr4运行时
4.7.1
编辑:添加build helper maven plugin相同的结果-类位于生成的jar的根文件夹中,但将使用它们的模块不会拾取类

在此配置中还尝试了maven shade插件

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern></pattern>
                                    <shadedPattern>org.shaded.plexus.util.</shadedPattern>
                                    <excludes>
                                        <exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>
                                        <exclude>org.codehaus.plexus.util.xml.pull.*</exclude>
                                    </excludes>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

org.apache.maven.plugins
maven阴影插件
3.2.1
包裹
阴凉处
org.shade.plexus.util。
org.codehaus.plexus.util.xml.Xpp3Dom
org.codehaus.plexus.util.xml.pull*

不同的jar,但有一些结果——在jar中,类位于:org/shade/plexus/util/下,但模块无法导入类

不是一个完美的解决方案,而是一个解决方案:

在这种情况下,他们说您可以在*.g文件的@header标记中添加包名。不幸的是,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标记中添加包名。不幸的是,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>

但是,使用此解决方案,您无法在不同的包中生成不同的语法

你可能会发现这里的答案很有帮助。它描述了如何添加一个Extra源目录,您可以使用它来包含生成的antlr源。你可能会发现这里的答案很有帮助。它描述了如何添加一个Extra源目录,您可以使用它来包含生成的antlr源。