无法在使用Maven时在Ubuntu 18.04上找到’tools.jar’。

huangapple go评论99阅读模式
英文:

Cannot find 'tools.jar' on ubuntu 18.04 when using maven

问题

我尝试使用Maven构建自定义的Jenkins插件。以下是问题:

我的项目依赖于org.kohsuke.args4j(https://github.com/kohsuke/args4j)。我已经在我的pom.xml文件中添加了依赖。

  <dependencies>
    <dependency>
      <groupId>org.kohsuke.metainf-services</groupId>
      <artifactId>metainf-services</artifactId>
      <version>1.1</version>
    </dependency>
    <dependency>
      <groupId>org.kohsuke.args4j</groupId>
      <artifactId>args4j-maven-plugin</artifactId>
      <version>2.33</version>
    </dependency>
  </dependencies>  

问题

显然,这个项目需要tools.jar可执行文件,但无法找到。

[ERROR] Failed to execute goal on project commit-pipeline-xml: Could not resolve dependencies for project com.siemens.plugins:commit-pipeline-xml:hpi:0.1: Could not find artifact jdk:tools:jar:5.0 at specified path /usr/local/java/jdk-14.0.2/../lib/tools.jar

对于我的安装(见下一段),路径无论如何都是错误的,但我甚至在*/usr/local/java/jdk-14.0.2/lib/tools.jar中找不到tools.jar文件,我本来希望在那里找到这个文件。ls -l on $JAVA_HOME/lib输出一些文件(主要是.so),但没有tools.jar。还有find $JAVA_HOME -name "tools"也没有找到任何东西。


jdk的安装

为了构建我的项目,我使用基于Ubuntu 18.04的docker。JDK是通过从oracle.com下载tar.gz文件并使用以下命令安装的:


mkdir -p /usr/local/java
cd /usr/local/java
tar xzvf "$JAVA_JDK_PATH"
ls -l ./jdk-$JAVA_JDK_VERSION/bin
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-$JAVA_JDK_VERSION/bin/java" 1 
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-$JAVA_JDK_VERSION/bin/javac" 1
sudo update-alternatives --set javac "/usr/local/java/jdk-$JAVA_JDK_VERSION/bin/javac"
ls -ld /usr/bin/java*
ls -ld /etc/alternatives/java*

$JAVA_JDK_PATH表示已下载zip文件的路径,$JAVA_JDK_VERSION表示要下载的JDK版本。

注意:我假设安装正常工作,因为我通常可以构建其他Maven项目。

如何安装JDK以获取tools.jar文件?
1: https://www.oracle.com/java/technologies/javase-jdk14-downloads.html

英文:

I tried building a custom Jenkins-Plugin using Maven. Here is the issue:

My project depends on org.kohsuke.args4j (https://github.com/kohsuke/args4j). I've added the dependency in my pom.xml-file.

  <dependencies>
    <dependency>
      <groupId>org.kohsuke.metainf-services</groupId>
      <artifactId>metainf-services</artifactId>
      <version>1.1</version>
    </dependency>
    <dependency>
      <groupId>org.kohsuke.args4j</groupId>
      <artifactId>args4j-maven-plugin</artifactId>
      <version>2.33</version>
    </dependency>
  </dependencies>  

The Problem

Apparently, this project requires somehow the tools.jar executable - which cannot be found.

[ERROR] Failed to execute goal on project commit-pipeline-xml: Could not resolve dependencies for project com.siemens.plugins:commit-pipeline-xml:hpi:0.1: Could not find artifact jdk:tools:jar:5.0 at specified path /usr/local/java/jdk-14.0.2/../lib/tools.jar

For my installation (see next paragraph) the path is wrong anyways, but I cannot even find tools.jar in /usr/local/java/jdk-14.0.2/lib/tools.jar where I would expect this file. A ls -l on $JAVA_HOME/lib outputs some files (mostly *.so) but no tools.jar. Also find $JAVA_HOME -name "tools" exposes nothing.


Installation of the jdk

For building my project the I'm using docker with ubuntu 18.04 as base. The jdk gets installed by downloading the tar.gz from oracle.com and installing it using the commands:


mkdir -p /usr/local/java
cd /usr/local/java
tar xzvf "$JAVA_JDK_PATH"
ls -l ./jdk-$JAVA_JDK_VERSION/bin
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-$JAVA_JDK_VERSION/bin/java" 1 
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-$JAVA_JDK_VERSION/bin/javac" 1
sudo update-alternatives --set javac "/usr/local/java/jdk-$JAVA_JDK_VERSION/bin/javac"
ls -ld /usr/bin/java*
ls -ld /etc/alternatives/java*

$JAVA_JDK_PATH denotes the path of the downloaded zip-file and $JAVA_JDK_VERSION the jdk-version to download.

Note: I assume the installation works, since I can typically build other maven projects.

How to I install the jdk in order to get the tools.jar file?

答案1

得分: 0

这似乎在JDK9之后不再可能,根据@Hans和这个帖子

已关闭。

英文:

Apparently, this is not possible any more since JDK9, according to @Hans and this post.

Closed.

huangapple
  • 本文由 发表于 2020年8月7日 15:53:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63297562.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定