我最近在我的 Macbook Pro 上升级到 Java7。我下载了 JDK(不是 JRE)。
» javac version
javac 1.7.0_17
» echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
但是,当尝试运行构建时,其中一个 Maven 编译器插件失败,声称我安装了 JRE:
» mvn install
[ERROR] execute error
org.apache.maven.plugin.MojoExecutionException: You need to run build with JDK
or have tools.jar on the classpath.
If this occures during eclipse build make sure you run eclipse under JDK as well
at com.mysema.maven.apt.AbstractProcessorMojo.execute(AbstractProcessorMojo.java:263)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
我很困惑,因为我显然安装了 JDK。我的 MAVEN_OPTS 没有做任何有趣的事情:
» echo $MAVEN_OPTS
-Xmx512m
尝试调试时,我检查了 source有问题的插件,它正在执行以下操作:
try {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new MojoExecutionException("You need to run build with JDK or have tools.jar on the classpath."
+ "If this occures during eclipse build make sure you run eclipse under JDK as well");
}
这似乎没什么害处,所以我怀疑我的命令行环境有问题,并写了一个简单的测试:
// Main.java
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class Main {
public static void main(String[] args) {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null)
{
System.out.print("Compiler is null");
} else {
System.out.print("Compiler is not null");
}
}
}
» javac Main.java
Main.java:1: cannot access javax.tools.JavaCompiler
bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar(javax/tools/JavaCompiler.class)
class file has wrong version 51.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
import javax.tools.JavaCompiler;
^
1 error
如果我对这个错误的理解是正确的,它表明一个针对 Java5 rt.jar 运行的 Java7 编译器?
我不确定这里发生了什么。
我明明装了Java7的JDK,但是不明白:
答案暗示 JRE/JDK 安装一团糟。我同意这似乎很可能,但很难找到罪魁祸首。
一些附加信息:
» which javac
/usr/bin/javac
ls -ltra /usr/bin/javac
/usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
cd /System/Library/Frameworks/JavaVM.framework/Versions
ls -ltra
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4 -> CurrentJDK
drwxr-xr-x 8 root wheel 272 18 Feb 08:39 A
drwxr-xr-x 11 root wheel 374 18 Feb 08:39 ..
lrwxr-xr-x 1 root wheel 1 14 Jun 11:14 Current -> A
lrwxr-xr-x 1 root wheel 58 14 Jun 11:15 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents
drwxr-xr-x 11 root wheel 374 14 Jun 11:15 .
因此,正在运行的 javac 是安装在 A/Commands 中的那个。我不确定这是否正确。从我的 Windows 时代来看,这似乎是错误的,但我对 Mac 如何处理 Java 安装以进行修补还不够熟悉。
我的$JAVA_HOME指向/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home,里面有如下内容:
drwxrwxr-x 10 root wheel 340 5 Feb 08:10 jre
-rw-rw-r-- 1 root wheel 123324 5 Feb 08:10 THIRDPARTYLICENSEREADME-JAVAFX.txt
drwxrwxr-x 5 root wheel 170 5 Feb 08:10 man
drwxrwxr-x 9 root wheel 306 2 Mar 02:10 db
-rw-rw-r-- 1 root wheel 3339 2 Mar 02:10 COPYRIGHT
drwxrwxr-x 9 root wheel 306 2 Mar 02:10 include
-rw-rw-r-- 1 root wheel 19997030 2 Mar 02:10 src.zip
-rw-rw-r-- 1 root wheel 447 2 Mar 02:10 release
-rw-rw-r-- 1 root wheel 172252 2 Mar 02:10 THIRDPARTYLICENSEREADME.txt
-rw-rw-r-- 1 root wheel 114 2 Mar 02:10 README.html
-rw-rw-r-- 1 root wheel 40 2 Mar 02:10 LICENSE
drwxrwxr-x 5 root wheel 170 2 Mar 02:10 ..
drwxrwxr-x 15 root wheel 510 2 Mar 02:13 .
drwxrwxr-x 13 root wheel 442 2 Mar 02:13 lib
drwxrwxr-x 43 root wheel 1462 2 Mar 02:13 bin
最佳答案
我在 /Library/Java/Extensions 中找到了一个 tools.jar
我不确定这是否是标准的。
但是,将 JDK7 $JAVA_HOME/lib 中的 tools.jar 复制到 /Library/Java/Extensions 解决了我所有的问题。
我还应该指出,在我最初的问题中,我已经将 Java CurrentSDK 更新为指向 JDK7:
CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents
正如指出的那样,这是一个坏主意 here .
我更新了它以指向 1.6。虽然这似乎违反直觉,但它是让事情正常进行所必需的。
带有 1.7 JDK 的 /System/Library/Frameworks/JavaVM.framework/Versions 的当前 list 如下所示:
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4 -> CurrentJDK
drwxr-xr-x 8 root wheel 272 18 Feb 08:39 A
drwxr-xr-x 11 root wheel 374 18 Feb 08:39 ..
lrwxr-xr-x 1 root wheel 1 14 Jun 11:35 Current -> A
lrwxr-xr-x 1 root wheel 59 14 Jun 12:31 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
drwxr-xr-x 11 root wheel 374 14 Jun 12:31 .
关于java - 升级到 Java7 后构建失败,缺少 Tools.jar 和错误的类版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17099379/
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
如果我使用ruby版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更
我安装了ruby版本管理器,并将RVM安装的ruby实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby。有没有办法让emacs像shell一样尊重ruby的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我最近决定从我的系统中卸载RVM。在thispage提出的一些论点说服我:实际上,我的决定是,我根本不想担心Ruby的多个版本。我只想使用1.9.2-p290版本而不用担心其他任何事情。但是,当我在我的Mac上运行ruby--version时,它告诉我我的版本是1.8.7。我四处寻找如何简单地从我的Mac上卸载这个Ruby,但奇怪的是我没有找到任何东西。似乎唯一想卸载Ruby的人运行linux,而使用Mac的每个人都推荐RVM。如何从我的Mac上卸载Ruby1.8.7?我想升级到1.9.2-p290版本,并且我希望我的系统上只有一个版本。 最佳答案