“javax.inject包不存在”在命令行中用javac编译时出错 [英] "package javax.inject does not exist" error while compiling with javac in commandline

查看:2205
本文介绍了“javax.inject包不存在”在命令行中用javac编译时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向学习JSF迈出第一步。我发现了一本名为Core JavaServer Faces Third Edition的有趣书。



试着编译第一个例子,你可以从以下地址下载源代码: http://horstmann.com/corejsf/ 。当我在命令行中输入以下内容时:

pre $ c $ UserBean.java

我得到错误:

  package javax.inject does不存在
包javax.enterprise.context doe不存在

我已经下载了Java EE, Ant和GlassFish。



下面是我的命令行快照:

  C:\JSF-Tutorial\corejsf3-examples\javaee\ch01\login\src\java\com\corejsf> javac UserBean.java 
UserBean.java:4 :错误:包javax.inject不存在
import javax.inject.Named;
^
UserBean.java:6:错误:包javax.enterprise.context不存在
import javax.enterprise.context.SessionScoped;
^
UserBean.java:9:错误:无法找到符号
@Named(user)//或@ManagedBean(name =user)
^
符号:class命名
UserBean.java:10:错误:找不到符号
@SessionScoped
^
符号:class SessionScoped
4错误

C:\JSF-Tutorial\corejsf3-examples\javaee\ch01\login\src\java\com\corejsf>

一直在搜索如何在上周编译Java EE应用程序,但没有任何用处。



有人会帮我解决这个问题,我需要解决这个问题,这样我才能继续学习JSF。



SP:
在转向使用NetBeans编译我的Java EE项目之前,我想学习如何编译Java EE应用程序。
我更喜欢学习如何使用GlassFish,然后也许后者我会考虑Tomcat。



还有一个问题:使用Java EE和GlassFish服务器部署我的应用程序有何区别?

在编译时classpath中的类。



在您使用GlassFish服务器的情况下,这就是 /glassfish/lib/javaee.jar 。您可以指定类路径为 -cp (或 -classpath )参数 javac code>命令。它是一个分号分隔的磁盘文件系统路径,指向应该包含在编译时类路径中的JAR文件和/或类文件夹。

  javac -cp /path/to/glassfish/lib/javaee.jar UserBean.java 

> javac 然后在它遇到一个被 import 引用的未知类时, ,这样它就可以验证你是否正确地使用了它。



这在技术上与Java EE无关。这只是基本的Java。我建议在深入Java EE之前先学习一下。



如果您使用的是IDE,那么只需将目标服务器附加为目标运行时添加到项目中。然后,IDE将自动完成构建路径的所有魔术(编译时类路径)。


I'm making my first steps toward learning JSF. I found this interesting book called "Core JavaServer Faces Third Edition".

Trying to compile the first example, you can download the source code from: http://horstmann.com/corejsf/. When I type the following on the command-line

javac UserBean.java

I get errors:

package javax.inject does not exist
package javax.enterprise.context doe not exist

I have downloaded Java EE, Ant and GlassFish.

Here is a snap of my command-line:

C:\JSF-Tutorial\corejsf3-examples\javaee\ch01\login\src\java\com\corejsf>javac UserBean.java
UserBean.java:4: error: package javax.inject does not exist
import javax.inject.Named;
                   ^
UserBean.java:6: error: package javax.enterprise.context does not exist
import javax.enterprise.context.SessionScoped;
                               ^
UserBean.java:9: error: cannot find symbol
@Named("user") // or @ManagedBean(name="user")
 ^
  symbol: class Named
UserBean.java:10: error: cannot find symbol
@SessionScoped
 ^
  symbol: class SessionScoped
4 errors

C:\JSF-Tutorial\corejsf3-examples\javaee\ch01\login\src\java\com\corejsf>

Been googling how to compile a Java EE application for the last week but without anything useful.

Would someone help me with this please, I need to solve this so I can move forward in my task to learn JSF.

S.P: I want to learn to compile Java EE applications bare hands before moving to compiling my Java EE projects with NetBeans. I prefer to learn to work with GlassFish first then maybe latter I'll consider Tomcat.

One more question; what's the difference between using Java EE and the GlassFish server to deploy my applications?

解决方案

You need to include the JAR file containing those classes in the compile time classpath.

In your particular case with the GlassFish server, that's the /glassfish/lib/javaee.jar. You can specify the classpath as -cp (or -classpath) argument of javac command. It is a semicolonseparated string of disk file system paths pointing to JAR files and/or class folders which should be included in the compile time classpath.

javac -cp /path/to/glassfish/lib/javaee.jar UserBean.java

javac will then look in there once it encounters an unknown class which is referenced by import, so that it can among others verify if you used it the right way.

This has technically nothing to do with Java EE. This is just basic Java. I'd suggest to learn that first before diving into Java EE.

In case you're using an IDE, then it's just a matter of attaching the target server as "Targeted Runtime" to the project. The IDE will then automatically do all magic as to the build path (the compile time classpath).

这篇关于“javax.inject包不存在”在命令行中用javac编译时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆