将我现有的Netbeans上的java项目移植到另一台机器上,然后运行它会产生一个不支持的ClassVersionError
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I started coding for a client-server machine on java, using RMI(Remote Method Invocation). The code works fine on my machine. It basically gives commands to the client machine and the client processes these commands and responds accordingly. After executing the command, the machine sends back its status to the server. An example would be, the server requests for an image feed from the client and the client returns an image to the server.

I used git to clone the current project and push it to another machine. When I execute the client side code, it works completely fine and the other machine(to which I pushed the source) responds the way it should.

However, when I run the server side code to code on the other machine, it gives a cryptic error that says:

C:\Users\RdX\Desktop\Thiswa
javax.naming.NamingException [Root exception is java.rmi.ServerError: Error occurred in          server thread; nested exception is: 
java.lang.UnsupportedClassVersionError: javadrone/Server (Unsupported major.minor   version 51.0)]
at com.sun.jndi.rmi.registry.RegistryContext.rebind(RegistryContext.java:159)
at com.sun.jndi.toolkit.url.GenericURLContext.rebind(GenericURLContext.java:249)
at javax.naming.InitialContext.rebind(InitialContext.java:427)
at javadrone.server.ServerImpl.<init>(ServerImpl.java:46)
at javadrone.server.DroneServer.<init>(DroneServer.java:45)
at javadrone.server.DroneServer.main(DroneServer.java:84)
Caused by: java.rmi.ServerError: Error occurred in server thread; nested exception is: 
java.lang.UnsupportedClassVersionError: javadrone/Server (Unsupported major.minor    version 51.0)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:349)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:207)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at     sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.rebind(RegistryContext.java:157)
...5 more

On inspecting the stack trace, the code that generates the exception is:

package javadrone.server;


import javadrone.Drone;
import javadrone.Server;

import javadrone.command.CommandQueue;


import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import java.util.HashMap;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public abstract class ServerImpl extends UnicastRemoteObject implements Server {
public static final String            RMI_PROT = "rmi:";
private static Context                namingContext;
private static HashMap<String, Drone> registeredDrones;
private String                        name;

public ServerImpl(String name) throws RemoteException, NamingException {
    this.name     = name;
    namingContext = new InitialContext();
    namingContext.rebind(RMI_PROT + name, ServerImpl.this);
    registeredDrones = new HashMap<>();
}

@Override
public String getName() throws RemoteException {
    return name;
}

@Override
public Drone registerDrone(String droneName) throws RemoteException {
    System.out.println("Remote client registered...");

    DroneImpl d = new DroneImpl(new CommandQueue(), droneName);

    registeredDrones.put(droneName, d);
    hasRegistered(d);

    return d;
}

public Drone getDrone(String droneName) {
    return registeredDrones.get(droneName);
}

@Override
public long getTime() throws RemoteException {
    return System.currentTimeMillis();
}

public abstract void hasRegistered(DroneImpl d);
}

To be specific,

namingContext.rebind(RMI_PROT + name, ServerImpl.this)

is the line that generates the error.

I searched a lot of places and they say that when the JDK compliler is of a higher version than the JRE version, it may produce such an error.

However I uninstalled all prior JDKs and JREs and recompiled the code after installing JDK 7.03. It still gives the same exception.

Why is this happening and how do I correct it?

#0

You may think you've removed all the other JDKs and JREs, but I strongly suspect you haven't really.

You haven't said how you're running the server code, but I suggest you log System.getProperty("java.version") as early as you can - I'm sure you'll find you're using an earlier JRE than you think you are.

Classfile version 51.0 is Java 7, which makes sense if you compiled it with JDK 7. It's just what you're using to run the code which is the problem.

If you're just running:

java ...

from the command line, I suggest you try explicitly running a particular version of Java, including the full path to the executable.

推荐文章

使用Javascript更改HiddenField值在C#codebhind中不更改

使用Javascript更改HiddenField值在C#codebhind中不更改

推荐文章

OpenGL——一次渲染多个网格,并进行单独的变换

OpenGL——一次渲染多个网格,并进行单独的变换

推荐文章

android的I/O问题(主要是ObjectInputStream)

android的I/O问题(主要是ObjectInputStream)

推荐文章

从其他函数返回的mysql_query不起作用?

从其他函数返回的mysql_query不起作用?

推荐文章

来自字符串变量concatation的Ruby变量

来自字符串变量concatation的Ruby变量

推荐文章

如何获取选定的文本id并用javascript保持标记的完整性来替换文本?

如何获取选定的文本id并用javascript保持标记的完整性来替换文本?

推荐文章

Mysql在添加一个表作为脚本时出错

Mysql在添加一个表作为脚本时出错

推荐文章

“编译”python脚本

“编译”python脚本

推荐文章

如何将值传递给构造函数?

如何将值传递给构造函数?

推荐文章

StreamWriter有时会清除我的文件

StreamWriter有时会清除我的文件

推荐文章

将优FILE_uu宏作为参数传递

将优FILE_uu宏作为参数传递

推荐文章

从c中的标准输入读取到EOF

从c中的标准输入读取到EOF

推荐文章

DirectX11设置着色器常量

DirectX11设置着色器常量

推荐文章

GeoJson世界数据库

GeoJson世界数据库

推荐文章

Capistrano部署中的“Gem bundler未安装”

Capistrano部署中的“Gem bundler未安装”

推荐文章

来自多个表的数据,并在select中使用count()

来自多个表的数据,并在select中使用count()