无法导入 JAR 文件?

huangapple go评论76阅读模式
英文:

Unable to import JAR files?

问题

我需要一个特定的JAR文件来执行代码。我可以通过将JAR文件添加到库中在eclipse中运行代码。

但是当我从命令提示符运行代码时,我会收到错误,指出无法导入javax.jms(该jar文件)。

C:\tibco\ems\8.5\samples\java\JNDI>javac tibjmsJNDIFT.java
tibjmsJNDIFT.java:43: error: package javax.jms does not exist
import javax.jms.*;
^
tibjmsJNDIFT.java:108: error: cannot find symbol
                        ConnectionFactory connectionFactory =
                        ^
  symbol:   class ConnectionFactory
  location: class tibjmsJNDIFT
tibjmsJNDIFT.java:109: error: cannot find symbol
                        (ConnectionFactory)jndiContext.lookup(factory[j]);
                         ^
  symbol:   class ConnectionFactory
  location: class tibjmsJNDIFT
3 errors

C:\tibco\ems\8.5\samples\java\JNDI>
英文:

I need a particular JAR file, fo execute a code. I am able to run the code In eclipse by adding the JAR file to libraries.

But when I run he code from cmd prompt I get error saying unable to import javax.jms(the jar file).

C:\tibco\ems.5\samples\java\JNDI>javac tibjmsJNDIFT.java
tibjmsJNDIFT.java:43: error: package javax.jms does not exist
import javax.jms.*;
^
tibjmsJNDIFT.java:108: error: cannot find symbol
                        ConnectionFactory connectionFactory =
                        ^
  symbol:   class ConnectionFactory
  location: class tibjmsJNDIFT
tibjmsJNDIFT.java:109: error: cannot find symbol
                        (ConnectionFactory)jndiContext.lookup(factory[j]);
                         ^
  symbol:   class ConnectionFactory
  location: class tibjmsJNDIFT
3 errors

C:\tibco\ems.5\samples\java\JNDI>

答案1

得分: 1

你应该使用"-cp"或"-classpath"选项:

javac -cp ".:/path/to/jms.jar:/path/to/any-other.jar" tibjmsJNDIFT.java

在Windows操作系统上,你可能需要使用"分号" (;) 而不是"冒号" (:)

英文:

You should use the "-cp" or "-classpath" option:

javac -cp ".:/path/to/jms.jar:/path/to/any-other.jar" tibjmsJNDIFT.java

On Windows OS you might have to use "semicolons" (;) instead of "colons" (:)

huangapple
  • 本文由 发表于 2020年8月17日 13:14:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63444910.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定