how do I execute a JAR and also add another JAR to the classpath? [duplicate]

半腔热情 提交于 2019-12-13 07:41:23

问题


How do I execute HelloClient.jar with openejb-client on the classpath?

thufir@doge:~$ 
thufir@doge:~$ java -cp -jar NetBeansProjects/HelloClient/dist/HelloClient.jar; apache-openejb-4.7.1/lib/openejb-client-4.7.1.jar org.acme.HelloClient
Error: Could not find or load main class NetBeansProjects.HelloClient.dist.HelloClient.jar
apache-openejb-4.7.1/lib/openejb-client-4.7.1.jar: line 1: $'PK\003\004': command not found
apache-openejb-4.7.1/lib/openejb-client-4.7.1.jar: line 2: $'\250m,E': command not found
apache-openejb-4.7.1/lib/openejb-client-4.7.1.jar: line 3: $'\b\247m,Ey\037\030': command not found
apache-openejb-4.7.1/lib/openejb-client-4.7.1.jar: line 4: syntax error near unexpected token `)'
apache-openejb-4.7.1/lib/openejb-client-4.7.1.jar: line 4: `META-INF/MANIFEST.MF�V]S�0}�L�C�gq�� ,;�#����NhC��I7I���MZ)���6�����s��T���Q�|o�Τ2�#��HBC$U�IF�%�2����q�gJ�7���:������<;���'�:C|�n;�����Q���Kq-il�`���W�N�X����:�x�񒈘SU'
thufir@doge:~$ 

Do I have to make the jar on the classpath executable?

see also:

http://openejb.apache.org/hello-world.html


回答1:


per Matz:

thufir@doge:~$ 
thufir@doge:~$ java -classpath .:NetBeansProjects/HelloClient/dist/HelloClient.jar:apache-openejb-4.7.1/lib/openejb-client-4.7.1.jar org.acme.HelloClient
Exception in thread "main" java.lang.NoClassDefFoundError: javax/ejb/EJBHome
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
    at javax.naming.InitialContext.init(InitialContext.java:242)
    at javax.naming.InitialContext.<init>(InitialContext.java:216)
    at org.acme.HelloClient.main(HelloClient.java:15)
Caused by: java.lang.ClassNotFoundException: javax.ejb.EJBHome
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 9 more
thufir@doge:~$ 
thufir@doge:~$ 


来源:https://stackoverflow.com/questions/28913444/how-do-i-execute-a-jar-and-also-add-another-jar-to-the-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!