eclipse 从 xsd 文件生成 Java 类 - JAXB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6697496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:17:59  来源:igfitidea点击:

Producing java classes from xsd file - JAXB

eclipseeclipse-pluginjaxb

提问by RKodakandla

I'm trying to learn to produce webservices with Java. I have added JAXB plugin to eclipse/plugin folder and I restarted eclipse. I have added a .xsd file to the source folder under eclipse and I am trying to generate classes from the xsd file. The tutorial mentions that, when I right click on the .xsd file, I should see an option called "JAXB 2.1 - > run XJC", but I don't see any such option on my eclipse installation. I only see "Generate - > JAXB Classes option". If I select this option and force it build classes, it gives out an error saying:

我正在尝试学习使用 Java 生成网络服务。我已将 JAXB 插件添加到 eclipse/plugin 文件夹并重新启动了 eclipse。我已经在 eclipse 下的源文件夹中添加了一个 .xsd 文件,我正在尝试从 xsd 文件生成类。该教程提到,当我右键单击 .xsd 文件时,我应该会看到一个名为“JAXB 2.1 - > 运行 XJC”的选项,但在我的 eclipse 安装中没有看到任何此类选项。我只看到“生成 - > JAXB 类选项”。如果我选择这个选项并强制它构建类,它会给出一个错误说:

The classpath for this project does not appear to contain the necessary libraries to proceed with class generation.
Please insure that a JAXB implementation is available on the classpath. Couldn't find the main class com.sun.tools.xjc.XJFacade.

Can someone help me to figure out why am I not seeing that option under eclipse? I tried both galileo and Helios.

有人可以帮我弄清楚为什么我在 eclipse 下看不到那个选项吗?我试过伽利略和太阳神。

回答by ragav

Check with the installed JRE in eclipse

在 Eclipse 中检查已安装的 JRE

Preference > Java > Installed JRE

首选项 > Java > 已安装的 JRE

If it points to jre then point it to jdk installation directory. It fixed the error for me

如果指向jre则指向jdk安装目录。它为我修复了错误

回答by Harsh Maheswari

Go to Window-> Preference -> Installed JREs

转到窗口-> 首选项-> 已安装的 JRE

If You are pointing to JRE point to JDK issue will be resolved

如果您指向 JRE 指向 JDK 问题将得到解决

enter image description here

在此处输入图片说明

回答by bdoughan

The Eclipse Daliproject (part of the Eclipse Web ToolsProject) has introduced new JAXB tooling that is available in the Indigo releaseof Eclipse:

Eclipse的大理项目(部分Eclipse Web工具项目)引入了新的JAXB工具是在现有的靛蓝发布的Eclipse:

回答by stacksonstacks

Sorry to necromance this post!

对不起,死灵这个帖子!

On linux distros this may be a result of using openjdk-*packages rather than the oracle ones. Offical oracle java can be installed following this tutorial

在 linux 发行版上,这可能是使用openjdk-*包而不是 oracle 的结果。可以按照本教程安装官方oracle java

Any time I see sunmentioned in the exception it usually comes back to open-jdkvs oracle-jdk

任何时候我看到sun异常中提到它通常会回到open-jdkvsoracle-jdk