Class not found / wrong name when using wsgen

3.1k views Asked by At

I'm having an issue with wsgen and while I've seen some answers that worked none of those solutions seems to be working for me. I believe the problem is related to the structure of the source and binaries.

My WSTest project is setup with the following folders:

bin
└───com
    └───example
        └───ws
src
└───com
    └───example
        └───ws

The main class is Test which resides in package com.example.ws.

I'm running wsgen from the main project folder WSTest using the following command:

wsgen -cp ./bin/com/example/ws -d ./src/com/example/ws -s ./src/com/example/ws Test

This results in:

Exception in thread "main" java.lang.NoClassDefFoundError (wrong name: com/example/ws/Test)

This makes sense since the class is part of a package. So I change my command to the following:

wsgen -cp ./bin/com/example/ws -d ./src/com/example/ws -s ./src/com/example/ws com.example.ws.Test

But now I get class not found from the wsgen tool:

Class not found: "com.example.ws.Test"

Usage: WSGEN [options]

What am I missing?

1

There are 1 answers

0
Bogdan On

Have you tried something like this?

wsgen -cp ./bin -d ./src -s ./src com.example.ws.Test

The classpath folder is were wsgen looks for class files. The package within the class is resolved to folder paths, so com.example.ws.Test should be a file like com/example/ws/Test.class within the bin classpath folder.

From the Java documentation:

Each classpath should end with a filename or directory depending on what you are setting the class path to:

  • For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
  • For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
  • For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).