相关疑难解决方法(0)

缺少工件com.sun:工具:jar

我一直在关注入门教程,但在使用Maven导入playn项目后卡住了.我正在使用在64位Windows 7上运行的Eclipse Indigo.

所有导入的项目都有相同的错误:

Missing Artifact com.sun:tools:jar in all the pom.xml files.
Run Code Online (Sandbox Code Playgroud)

经过几个小时的搜索论坛,我尝试过:

安装最新的Java 1.6.029更改JAVA_HOME环境变量以指向\program files\Java\jdk1.6_029 更改Eclipse Java首选项以使用JRE jdk1.6_029.

我真的想尝试playn,但为什么有一些帖子我似乎无法找到解决方案的共识答案.有人说Sun从64位jdk中删除了一些东西,其他人说你必须编辑你的xml文件,很多人说你已经改变了你的JAVA_HOME,另一个人说你必须改变Eclipse的VM选项.

任何有关清除此功能的帮助都会受到赞赏,并且可能对许多人有用,因为我这里没有特别奇怪的设置.

(编辑)这是第一个项目中的pom.xml.Eclipse标记行中的错误:

<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>

  <parent>
    <groupId>com.googlecode.playn</groupId>
    <artifactId>playn-project</artifactId>
    <version>1.1-SNAPSHOT</version>
  </parent>

  <artifactId>playn-android</artifactId>
  <name>PlayN Android</name>
  <packaging>jar</packaging>

  <repositories>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>com.googlecode.playn</groupId>
      <artifactId>playn-core</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- needed because Android uses the same JSON code as playn-java;
         that should be factored into a library shared by both backends -->
    <dependency>
      <groupId>com.googlecode.playn</groupId>
      <artifactId>playn-java</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency> …
Run Code Online (Sandbox Code Playgroud)

java maven playn

78
推荐指数
9
解决办法
16万
查看次数

JAVA_HOME被Maven破坏了

我正在使用统一的Maven构建来改进一堆现有的Java项目.由于每个项目都是成熟的并且已经建立了基于Ant的构建,所以我maven-antrun-plugin用来执行build.xml如下现有的:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <tasks>
                            <ant antfile="build.xml" target="compile" />
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

当我mvn compile使用此消息运行构建失败时:

[INFO] An Ant BuildException has occured: The following error occurred 
       while executing  this line:
build.xml:175: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Java\jdk1.6.0_13\jre"
Run Code Online (Sandbox Code Playgroud)

令我困惑的是

  1. 我有JAVA_HOME=C:\Java\jdk1.6.0_13我的环境设置的一部分,什么时候mvn.bat执行,这正是我得到的,但正如你在错误信息中看到它出现的那样C:\Java\jdk1.6.0_13\jre
  2. 如果我运行ant compile一切编译就好了 …

ant maven-2 maven

38
推荐指数
2
解决办法
1万
查看次数

声明对tools.jar的maven依赖以在JDK 9上工作

我有一个使用这种技术的项目在JDK 8及更早版本中运行良好.但是,在JDK 9中,这个jar被删除了,它不再起作用:

com.sun的"dependencies.dependency.systemPath":tools:jar指的是一个不存在的文件/usr/lib/jvm/java-9-jdk/../lib/tools.jar.请验证您使用JDK而不仅仅是JRE运行Maven.

(虽然JDK 9中没有 tools.jar ,但这条路看起来很奇怪)

什么是可以在JDK版本甚至JDK供应商中工作的最佳实践?我甚至没有在OpenJDK上找到JDK 9的任何解决方法(同时保持项目可在JDK 8上构建).

maven tools.jar java-9

13
推荐指数
3
解决办法
8980
查看次数

使用带注释的方法时使java编译器发出警告(如@deprecated)

假设我定义了一个名为的自定义注释@Unsafe.

我想提供一个注释处理器,它将检测注释方法的引用@Unsafe并打印警告.

例如,鉴于此代码......

public class Foo {
  @Unsafe
  public void doSomething() { ... }
}

public class Bar {
  public static void main(String[] args) {
    new Foo().doSomething();
  }
}
Run Code Online (Sandbox Code Playgroud)

...我希望编译器打印如下:

WARN > Bar.java, line 3 : Call to Unsafe API - Foo.doSomething()
Run Code Online (Sandbox Code Playgroud)

它在精神上非常相似@Deprecated,但我的注释是在传达不同的东西,所以我不能@Deprecated直接使用.有没有办法用注释处理器实现这一目标?注释处理器API似乎更关注应用注释的实体(Foo.java在我的示例中),而不是引用注释成员的实体.

此问题提供了一种使用ASM作为单独构建步骤实现它的技术.但我想知道我是否可以通过javac和注释处理以更自然的方式做到这一点?

java compiler-construction annotations deprecated

12
推荐指数
1
解决办法
1526
查看次数

Maven:缺少工件com.sun:tools:jar:POM.xml中的1.6.0编译时异常

当我尝试为工具添加依赖性时,我得到一个奇怪的问题并在我的pom.xml中获得编译时异常.jar显示如下(Missing artifact com.sun:tools:jar:1.6.0)

问题

我已将JAVA_HOME变量设置如下:

JAVA_HOME:C:\ Program Files\Java\jdk1.6.0_34

当我将它硬编码到JDK1.6的实际路径时,我没有发现任何错误,如下所示.

 <dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6.0</version>
   <scope>system</scope>
   <systemPath>C:\Program Files\Java\jdk1.6.0_34\lib\tools.jar</systemPath>
 </dependency>
Run Code Online (Sandbox Code Playgroud)

但我知道这不是好习惯.请求解决此错误的指导.

java maven-2 pom.xml maven-3 maven

5
推荐指数
1
解决办法
4万
查看次数

如何从ExecutableElement获取方法主体

在我的帮助下,AbstractProcessor我可以从带有某些注释的类中获取所有方法,我创建了:

List<? extends Element> allElements = processingEnv.getElementUtils().getAllMembers((TypeElement) bean);
List<ExecutableElement> methods = ElementFilter.methodsIn(allElements);
Run Code Online (Sandbox Code Playgroud)

是否可以获取方法的主体ExecutableElement?该API似乎只处理签名和修饰符。

我可能会使用以下答案的一些变体:https : //stackoverflow.com/a/34568708/6095334,以从专有* .sun。**包访问类,例如com.sun.tools.javac.tree.JCTree$MethodTree

MethodTree methodTree = trees.getTree(executableElement);
Run Code Online (Sandbox Code Playgroud)

这样,AbstractProcessor的init()方法treescom.sun.source.util.Treesset 的实例在哪里:trees = Trees.instance(processingEnv);
但是这些类带有警告:这不是任何受支持的API的一部分。如果编写依赖于此的代码,则后果自负。该代码及其内部接口如有更改或删除,恕不另行通知。

我希望可以从更通用的注释处理框架中访问带注释的方法的主体。

java methods annotation-processing

5
推荐指数
0
解决办法
1014
查看次数