在jcabi的主网页上,是在Maven之外使用的一个简单示例,它自称只需要一个Maven依赖项(jcabi 0.9)。我已经为这个“主”创建了一个项目,只是为了尝试它,但它似乎有一些,嗯,困难。
public class Main {
public static void main(String[] args) {
File local = new File("/tmp/local-repository");
Collection<RemoteRepository> remotes = Arrays.asList(
new RemoteRepository(
"maven-central",
"default",
"http://repo1.maven.org/maven2/"
)
);
Collection<Artifact> deps = new Aether(remotes, local).resolve( // #1
new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
"runtime"
);
}
}首先,#1生成此错误(来自Eclipse):
项目未构建,因为其构建路径不完整。无法找到org.apache.maven.project.MavenProject的类文件。修复生成路径,然后尝试构建此项目
所以..。没什么大不了的,我猜:我只会加入maven-project (2.2.1)。嘿,它会编译的!太棒了!但是,等一下,运行它时:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/maven/settings/building/SettingsBuildingException
at org.test.aether.Main.main(Main.java:23)嗯。好的,我还会加入maven-settings (3.3.2)。现在我们该走了..。对吗?嗯,不:这次,我得到了大量的异常输出,如下所示:
java.lang.instrument.IllegalClassFormatException: Error while instrumenting class com/jcabi/aether/Aether.
at org.jacoco.agent.rt.internal_9dd1198.CoverageTransformer.transform(CoverageTransformer.java:89)
at sun.instrument.TransformerManager.transform(TransformerManager.java:169)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:365)别误会我的意思。听起来是个很棒的项目。但它真的起作用吗?头版的例子是怎么回事?有人对此有经验吗?
发布于 2015-06-29 21:38:08
从https://github.com/jcabi/jcabi-aether/blob/master/src/main/java/com/jcabi/aether/Aether.java的jcabi-aether的github代码中,我们确实需要添加以下两个依赖项:
我添加了这些并获得了运行示例代码。
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.resolution.DependencyResolutionException;
import org.sonatype.aether.util.artifact.DefaultArtifact;
import com.jcabi.aether.Aether;
public class RunAether {
public static void main(String[] args) throws DependencyResolutionException {
File local = new File("/tmp/local-repository");
Collection<RemoteRepository> remotes = Arrays.asList(
new RemoteRepository(
"maven-central",
"default",
"http://repo1.maven.org/maven2/"
)
);
Collection<Artifact> deps = new Aether(remotes, local).resolve(
new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
"runtime"
);
System.out.println("Got the Junit dependencies");
}
}我的pom文件依赖项:
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aether</artifactId>
<version>0.10</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.0.3</version>
</dependency>https://stackoverflow.com/questions/24925239
复制相似问题