NetBeans java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory] at javax.xml.bind.JAXB.unmarshal(JAXB.java:171)

huangapple 未分类评论46阅读模式
英文:

NetBeans java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory] at javax.xml.bind.JAXB.unmarshal(JAXB.java:171)

问题

我已将NetBeans更新到12版本我的应用程序是在Java 8中创建的我现在使用Java 14一切都在运行但出现了这个错误

    [java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
    	at javax.xml.bind.JAXB.unmarshal(JAXB.java:171)

我在Google上阅读了许多帖子但我无法找到解决方案
只有在我运行NetBeans应用程序时才会出现此错误如果我编译我的应用程序并运行它它可以正常运行没有错误

我还下载了jaxb-api-2.3.1.jar并添加到库中
编辑还尝试了jaxb-api-2.4.0-b180830.0359.jar没有成功

但真正疯狂的是如果我在终端中运行我的应用程序我会得到这个错误

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXB

只有在我当前文件夹中点击myApp.jar时它才能正常运行没有任何错误

有人有什么想法吗
对于这种行为有什么解决办法吗

提前致谢

编辑
目前我找到了一个解决办法但是伴随着这个警告

    警告发生了非法的反射访问操作
    警告非法的反射访问来自com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1 (file:/Applications/NetBeans/Apache%20NetBeans%2012.0.app/Contents/Resources/NetBeans/netbeans/ide/modules/ext/jaxb/jaxb-impl.jar)对方法java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)的访问java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
    警告请考虑将此情况报告给com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1的维护者
    警告使用--illegal-access=warn来启用进一步的非法反射访问操作警告
    警告在将来的版本中所有非法访问操作都将被拒绝

如果我使用此JAXB 2.2.5.jar库就会出现这个警告
不适用上述描述的JAXB版本

我的应用程序现在使用2.2.5运行但还能坚持多久

抱歉但我不知道如何通知开发人员我真的认为他们知道这个问题但遗憾的是它还没有被修复 :(

这是我的代码

```java
package Tools;

import Enums.Property;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JOptionPane;
import static Tools.Device.Director;
import javax.xml.bind.JAXB;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Device {

    @Override
    public String toString() {
        return DeviceName;
    }

    public static final String Separator = FileHandler.getFileSeparator();
    public static File Director = new File(Property.datarefBaseFile.getValue().substring(0, Property.datarefBaseFile.getValue().lastIndexOf(Separator)) + Separator + "Devices" + Separator);

    @XmlElement
    public String DeviceName;
    @XmlElement
    public String DevicePosX;
    @XmlElement
    public String DevicePosY;
    @XmlElement
    public String DeviceWidth;
    @XmlElement
    public String DeviceHeight;
    @XmlElement
    public String DeviceBackgroundImage;
    @XmlElement
    public String DeviceScaleX;
    @XmlElement
    public String DeviceScaleY;

    public List<ControlProps> controlsProps;

    public static Device load(String file) {
        return JAXB.unmarshal(new File(Director, file), Device.class);
    }

    public static File getDirector() {
        return Director;
    }

    public void save() {
        Director.mkdir();
        File file = new File(Director, DeviceName + ".xml");
        File fileback = new File(Director, DeviceName + ".bak");

        if (fileback.exists()) {
            fileback.delete();
            System.out.println(String.format("Device %s old deleted! %s", fileback, Utils.ShowTime()));
        }
        file.renameTo(fileback);

        if (fileback.exists()) {
            System.out.println(String.format("Device %s new created! %s", fileback, Utils.ShowTime()));
        }

        if (!file.exists()) {
            JAXB.marshal(this, file);
            String msg = String.format("Device %s saved! %s", file, Utils.ShowTime());
            System.out.println(msg);
        }

        if (!file.exists()) {
            String msg = String.format("Fatal error: %s was deleted an not created new!\nDevice crashed.\nRestore from %s file. %s", file, fileback, Utils.ShowTime());
            System.out.println(msg);
            MsgBox.error(msg);
        }

        if (!fileback.exists()) {
            String msg = String.format("Warning! Backupfile: %s was not created yet! %s", fileback, Utils.ShowTime());
            System.out.println(msg);
            MsgBox.error(msg);
        }
        //       JOptionPane.showMessageDialog(null, msg);
        //       LogFile.log(Level.INFO, new String[] {file.toString() + " saved"});
    }

    public int delete() {
        File fileBak = new File(Director, DeviceName + ".creater.bak");
        File file = new File(Director, DeviceName + ".xml");
        int response = 0;
        String msg = String.format("Delete this device: %s?", DeviceName);
        response = JOptionPane.showConfirmDialog(null, msg, "Confirm",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION && file.exists()) {
            file.renameTo(fileBak);
            file.delete();
            msg = String.format("File: %s deleted\nBackupfile %s was created!", file, fileBak);
            JOptionPane.showMessageDialog(null, msg);
        } else {
            msg = String.format("%s not deleted file: %s", DeviceName, file);
            JOptionPane.showMessageDialog(null, msg);
        }

        return response;
    }

    public Device() {
        controlsProps = new LinkedList<>();
    }

    public ControlProps find(String name) {
        for (ControlProps prop : controlsProps) {

            if (prop.ControlName.equals(name)) {
                return prop;
            }
        }
        throw new IllegalArgumentException("ControlName not found");
    }

    public void deleteControl(ControlProps controlProps

<details>
<summary>英文:</summary>

I have updated NetBeans to version 12. My Application was created in Java 8. I use now java 14. All is running but this:

    [java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
    	at javax.xml.bind.JAXB.unmarshal(JAXB.java:171)

I raead many posts in Google but i cant hit a solution.
This error occurs only if i run in NetBeans app. If i compile my app and run it it works without errors.

I habe also downloaded jaxb-api-2.3.1.jar and added to library.
Edit: Alos tryed jaxb-api-2.4.0-b180830.0359.jar. No success.

But realy crasy is, if i run my app in Terminal i get this error:

    Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: javax/xml/bind/JAXB

Only on click on myApp.jar in my current folder it runs without any error:

Has any body an idea?
What is a solution for this behavior?

Thanks in advance.

Edit:
For now i found a solution but whith this WARNING:

    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1 (file:/Applications/NetBeans/Apache%20NetBeans%2012.0.app/Contents/Resources/NetBeans/netbeans/ide/modules/ext/jaxb/jaxb-impl.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
    WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release

this appears if i use this JAXB 2.2.5.jar library. 
Dont work wit JAXB versions as described above.

My app runs now with 2.2.5 but how long?

Sorry but i have no idea how i can inform the developer. i.g. Sun or Marven or whoever. I true this issue is known there. But is bad that it isnt fixt yet. :(


This ist my code:

    package Tools;
    
    import Enums.Property;
    import java.io.File;
    import java.util.LinkedList;
    import java.util.List;
    import javax.swing.JOptionPane;
    import static Tools.Device.Director;
    import javax.xml.bind.JAXB;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    
    
        @XmlRootElement
        public class Device {
        
            @Override
            public String toString() {
                return DeviceName;
            }
        
            /**
             *
             */
            public static final String Separator = FileHandler.getFileSeparator();
            public static File Director = new File(Property.datarefBaseFile.getValue().substring(0, Property.datarefBaseFile.getValue().lastIndexOf(Separator)) + Separator + &quot;Devices&quot; + Separator);
        
            @XmlElement
            public String DeviceName;
            @XmlElement
            public String DevicePosX;
            @XmlElement
            public String DevicePosY;
            @XmlElement
            public String DeviceWidth;
            @XmlElement
            public String DeviceHeight;
            @XmlElement
            public String DeviceBackgroundImage;
            @XmlElement
            public String DeviceScaleX;
            @XmlElement
            public String DeviceScaleY;
        
            public List&lt;ControlProps&gt; controlsProps;
        
            public static Device load(String file) {
                return JAXB.unmarshal(new File(Director, file), Device.class);
            }
        
            public static File getDirector() {
                return Director;
            }
        
            public void save() {
                Director.mkdir();
                File file = new File(Director, DeviceName + &quot;.xml&quot;);
                File fileback = new File(Director, DeviceName + &quot;.bak&quot;);
        
                if (fileback.exists()) {
                    fileback.delete();
                    System.out.println(String.format(&quot;Device %s old deleted! %s&quot;, fileback, Utils.ShowTime()));
                }
                file.renameTo(fileback);
        
                if (fileback.exists()) {
                    System.out.println(String.format(&quot;Device %s new created! %s&quot;, fileback, Utils.ShowTime()));
                }
        
                if (!file.exists()) {
                    JAXB.marshal(this, file);
                    String msg = String.format(&quot;Device %s saved! %s&quot;, file, Utils.ShowTime());
                    System.out.println(msg);
                }
        
                if (!file.exists()) {
                    String msg = String.format(&quot;Fatal error: %s was deleted an not created new!\nDevice crashed.\nRestore from %s file. %s&quot;, file, fileback, Utils.ShowTime());
                    System.out.println(msg);
                    MsgBox.error(msg);
                }
        
                if (!fileback.exists()) {
                    String msg = String.format(&quot;Warning! Backupfile: %s was not created yet! %s&quot;, fileback, Utils.ShowTime());
                    System.out.println(msg);
                    MsgBox.error(msg);
                }
                //       JOptionPane.showMessageDialog(null, msg);
                //       LogFile.log(Level.INFO, new String[] {file.toString() + &quot; saved&quot;});
            }
        
            public int delete() {
                File fileBak = new File(Director, DeviceName + &quot;.creater.bak&quot;);
                File file = new File(Director, DeviceName + &quot;.xml&quot;);
                int response = 0;
                String msg = String.format(&quot;Delete this device: %s?&quot;, DeviceName);
                response = JOptionPane.showConfirmDialog(null, msg, &quot;Confirm&quot;,
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (response == JOptionPane.YES_OPTION &amp;&amp; file.exists()) {
                    file.renameTo(fileBak);
                    file.delete();
                    msg = String.format(&quot;File: %s deleted\nBackupfile %s was created!&quot;, file, fileBak);
                    JOptionPane.showMessageDialog(null, msg);
                } else {
                    msg = String.format(&quot;%s not deleted file: %s&quot;, DeviceName, file);
                    JOptionPane.showMessageDialog(null, msg);
                }
        
                return response;
            }
        
            public Device() {
                controlsProps = new LinkedList&lt;&gt;();
            }
        
            public ControlProps find(String name) {
                for (ControlProps prop : controlsProps) {
        
                    if (prop.ControlName.equals(name)) {
                        return prop;
                    }
                }
                throw new IllegalArgumentException(&quot;ControlName not found&quot;);
            }
        
            public void deleteControl(ControlProps controlProps) {
                String name = controlProps.ControlName;
                if (controlsProps.remove(controlProps)) {
                    save();
                    System.out.println(name + &quot; deleted&quot;);
                    //LogFile.log(Level.INFO, new String[]{name + &quot; deleted&quot;});
                }
            }
            
            
        }

</details>


huangapple
  • 本文由 发表于 2020年7月24日 16:49:44
  • 转载请务必保留本文链接:https://java.coder-hub.com/63070165.html
匿名

发表评论

匿名网友

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

确定