ntstha
ntstha

Reputation: 1173

run a class file inside a web project in linux

Lets say i have a class file A.class and i keep it inside some package of an already exisiting web project in deployed in glassfish server in linux. A.class has many dependent with many other classes in same package or other package of the same web project. Now i cd into the folder and try to run java A it throws following exception Exception in thread "main" java.lang.NoClassDefFoundError /path/A.Is it because the class file coulnot find its dependencies?. Is there any way to make it run.

Error log. Here the class file i want to run is ChangeBulkPassword

Exception in thread "main" java.lang.NoClassDefFoundError: com/project_name/ChangeBulkPassword
Caused by: java.lang.ClassNotFoundException: com.project_name.ChangeBulkPassword
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.project_name.ChangeBulkPassword. Program will exit.

Edit:

I cd to project_name\WEB-INF\classes and then run java packagename.ChangeBulkPassword.It throws exception that i cannot find required library.Is there a way to reference those libraries?

Upvotes: 0

Views: 56

Answers (1)

tianwei
tianwei

Reputation: 1879

If your A.class has a package name com.xxx.yyy there must be a directory tree com/xxx/yyy,you should cd to the directory where com directory exists and then run the class by type java com.xxx.yyy.A.

EDIT: If there is a directory tree: /home/me/webapps/com/project_name/ChangeBulkPassword

cd

cd webapps

java -classpath "." com.project_name.ChangeBulkPassword

Upvotes: 1

Related Questions