简体   繁体   中英

Invoke a Java class present in an ear from a shell script

I have a class dealerProfile.class in CompanyUS.ear which is deployed in the server. I wrote a simple shell script to invoke the class 'dealerProfile.class' 'com.download.DealerProfile' is the package the class is in

code dealerProfile.sh: java com.download.DealerProfile.testShellDealer

I am getting this error

Exception in thread "main" java.lang.NoClassDefFoundError: com.download.DealerProfile.testShellDealer
Caused by: java.lang.ClassNotFoundException: com.download.DealerProfile.testShellDealer
        at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:677)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:643)
Could not find the main class: com.download.DealerProfile.testShellDealer.  Program will exit.

I understand that I need to set class path to the class file location in .ear

but I dont know how to do it.

My first time posting a question so please excuse if it looks amatuer. Any suggestions greatly appreciated.

Thanks for your time to read the thread

EAR files are meant for deployment on a server like JBoss or similar. It is usual that it contains jar files and/or web archives (WAR files). Java runtime will not execute an EAR file as it will do for a Jar file (using java -jar) so you cannot use the command line for running a java executable. You should drop it into an application server or package your classes in a Jar file even allowing you to nest jar files in one another.

The command to run your class in a jar will look like:

java -jar CompanyUS.jar com.download.DealerProfile.testShellDealer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM