Java 从命令行编译,但不从 Maven 编译
我的系统设置为从命令行编译 jee6 代码(无 IDE)。我最近尝试编译一些使用 javax.enterprise.context.RequestedScope 的代码。代码从命令提示符编译得很好,但当我尝试使用 Maven 构建应用程序时,我不断收到 javax.enterprise.context package not found 错误。
什么给?我认为 Maven 使用的 javac 与我使用的相同。为什么javac可以找到包而Maven却找不到?我需要为java包添加依赖吗?
或者...有没有办法告诉 Maven 在构建时使用当前的类文件,或者 Maven 在构建时必须进行编译?
谢谢。
I have my system set up to compile jee6 code from the command line (no IDE). I recently tried to compile some code that uses javax.enterprise.context.RequestedScope. The code compiled fine from the command prompt but when I tried to build the application using Maven I keep getting javax.enterprise.context package not found error.
What gives? I thought Maven was using the same javac I'm using. Why can javac find the package but Maven can't? Do I need to add dependencies for java packages?
Or...is there a way to tell Maven to use the current class files when building or does Maven have to compile when it builds?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 Java EE 6 jar 添加到您的 Maven 依赖项:
这会将 Java EE 类添加到您的编译时类路径。
Try adding the Java EE 6 jar to your Maven dependencies:
This will add the Java EE classes to your compile-time classpath.
要使用 Maven 编译代码,您需要告诉它在哪里可以找到所需的组件。
看起来您需要将其添加到依赖项中:
请注意
元素。它告诉 Maven 不要将此依赖项与您的工件捆绑在一起,因为在运行时它将由应用程序容器提供。关于它从命令行编译的原因。
您可能在命令行
-cp
选项或全局CLASSPATH
变量中拥有所需的 jar 文件。Maven 在设计上并不关注全局
CLASSPATH
。To compile your code with Maven, you need to tell it where to find required components.
Looks like you need to add this to your dependencies:
Note the
<scope>
element. It tells Maven not to bundle this dependency with your artifact, because at run time it will be provided by the application container.On the reason why it compiles from the command line.
You probably have the required jar file on the command line
-cp
option or in your globalCLASSPATH
variable.Maven, by design, does not pay attention to the global
CLASSPATH
.