gpt4 book ai didi

java - 我如何使用 maven 构建 natty 有什么问题?

转载 作者:行者123 更新时间:2023-11-30 11:10:15 24 4
gpt4 key购买 nike

我正在尝试使用 NATTY通过将其作为 Maven 依赖项包含在内。我刚刚做了 Hello, World Maven tutorial -- 但我对 Maven 不熟悉。 natty 站点上的说明说要将 natty 作为依赖项包含在 pom.xml 中。我是这样做的

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.joestelmach</groupId>
<artifactId>natty</artifactId>
<version>0.9</version>
</dependency>
</dependencies>
</project>

然后我运行 $mvn package 并且项目构建成功。我在我的/target 中看到一个 jar 文件:my-app-1.0-SNAPSHOT.jar,因此我假设 natty 依赖项已烘焙到该 jar 中。

为了测试,我在名为 Temporary.java 的文件中创建了一个简单的类来保存 natty 演示代码:

import com.joestelmach.natty.*;
import com.joestelmach.natty.generated.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class Temporary{
public static void main(String [] args) {
Parser parser = new Parser();
List groups = parser.parse("the day before next thursday");
for (DateGroup group : groups) {
List dates = group.getDates();
int line = group.getLine();
int column = group.getPosition();
String matchingValue = group.getText();
String syntaxTree = group.getSyntaxTree().toStringTree();
Map parseMap = group.getParseLocations();
boolean isRecurreing = group.isRecurring();
Date recursUntil = group.getRecursUntil();
}
}
}

但是当我运行 $ javac -cp target/my-app-1.0-SNAPSHOT.jar Temporary.java 我得到

Temporary.java:1: error: package com.joestelmach.natty does not exist
import com.joestelmach.natty.*;

我做错了什么?

最佳答案

您需要确保在使用 Maven 打包 jar 时包含您的依赖项。

我相信你需要将它添加到你的 pom.xml

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass></mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

确保在运行它时使用末尾带有“jar-with-dependencies.jar”的 .jar。这将确保包含您的 natty 依赖项。

关于java - 我如何使用 maven 构建 natty 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27783505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com