Cannot find class in java

Refresh

March 2019

Views

67 time

1

Here is my directory

--MainFolder
----src
-------zad1
---------server
------------AddressInfoServer.class

Now, I am in folder server (MainFolder/src/zad1/server), and I am trying to run AddressInfoServer.class like this:

java AddressInfoServer

but I receive error of:

Could not find or load main class AddressInfoServer.class

Here is my compiled AddressInfoServer.class:

package zad1;

import javax.naming.InitialContext;
import zad1.AddressInfo;

public class AddressInfoServer {
    public AddressInfoServer() {
    }

    public static void main(String[] var0) {
        try {
            System.getProperties().put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
            System.getProperties().put("java.naming.provider.url", "iiop://localhost:3333");
            AddressInfo var1 = new AddressInfo();
            InitialContext var2 = new InitialContext();
            var2.rebind("AddressInfoService", var1);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }
}

What am I missing here?

3 answers

1

The package seems not correct.

A class present in a subdirectory zad1/server should have package

package zad1.server;

To launch it

java zad1.server.AddressInfoServer
0

There are two things:-

1) package declaration: package zad1.server;

2) run the class while you are at MainFolder/src and invoke java zad1.server.AddressInfoServer

Please tell me whether it works or not.

1

Your package is wrong. Since your class lives inside of zad1/server, your package needs to reflect this.

package zad1.server;

To invoke it, you'd use class' fully qualified name:

java zad1.server.AddressInfoServer