uksz
uksz

Reputation: 18699

Cannot find class in java

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?

Upvotes: 1

Views: 94

Answers (3)

Sanjeev Saha
Sanjeev Saha

Reputation: 2652

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.

Upvotes: 0

Davide Lorenzo MARINO
Davide Lorenzo MARINO

Reputation: 26926

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

Upvotes: 1

Makoto
Makoto

Reputation: 106389

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

Upvotes: 1

Related Questions