如何执行JAR并将另一个JAR添加到类路径?

时间:2015-03-07 09:42:14

标签: java jar classpath command-line-interface packages

如何在类路径上使用HelloClient.jar执行openejb-client

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:~$ 

我是否必须在类路径上执行jar?

另见:

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

1 个答案:

答案 0 :(得分:-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:~$