使用Maven,如何根据J2EE / JPA JAR正确部署WAR? [英] Using Maven, how to properly deploy WAR depending on J2EE/JPA JAR?
问题描述
我正在创建一个模块化的Maven项目。项目部署在Glassfish 3.1上。 Project(webapp)由三个模块组成:
两个WAR都使用来自Common的重注释(@Entity,@Inject,@EJB,...)类。目前常见的是JAR,但这不是必需的。问题是:如何正确部署这样的项目?
通过我目前的(受谷歌和stackoverflow影响的)知识:
$ b
-
常见的不能是JAR,因为.jar文件被放入JAR中的WEB-INF \ lib目录中。这使得部署时初始化成为可能,因为Glassfish期望.class并产生一个Unsatisfied dependencies错误,导致部署失败。
常见的不能是WAR,因为在构建之后使用WAR覆盖复制ocurrs - 导致依赖于自身的构建...
编辑
正如Mike Decks评论所示,建议设置正常,但我认为提供完整的错误消息会很有用:
模块的部署错误:用户:部署过程中发生错误:
加载应用程序时出现异常:WELD-001408类型为[身份验证]的不满意依赖项
限定符[@Default]在注入点
[[field] @Inject xxx.xxx.servlets.LoginFilter.authentication]。
这是什么意思? >我附上了相关的类(修剪了一下,即不是get / set方法,导入等)。 LoginFilter实现过滤器{
@Inject
认证认证;
$ b $ public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws IOException,ServletException {
HttpServletRequest httpRequest =(HttpServletRequest)请求;
LoginBean login =(LoginBean)httpRequest.getSession()。getAttribute(loginBean); $(b)if((login == null ||!login.isAuthenticated())){
HttpServletResponse httpResponse =(HttpServletResponse)响应;
String requestUrl = httpRequest.getRequestURI()。toString();
authentication.setNavigateAfterLogin(requestUrl);
httpResponse.sendRedirect(./../ login.html);
}
chain.doFilter(request,response);
$ b @Override
public void init(FilterConfig fConfig)throws ServletException {}
$ b $ @Override
public void destroy(){ }
}
和:
@SessionScoped
public class Authentication实现Serializable {
@Inject
private UserDatabaseController userDb;
私人ShopUser用户;
private String navigateAfterLogin;
私人字符串登录;
私人字符串密码;
public boolean doLogin(String username,String password){
List< ShopUser> users = userDb.getUsers(); (shopUser shopUser:users){
if(shopUser.getLogin()。equals(username)&& shopUser.getPassword()。equals(password)){
setUser shopUser);
返回true;
}
}
返回false;
}
public void doLogout(){
setUser(null);
public boolean isAuthenticated(){
return getUser()!= null;
问题通过添加空 I'm creating a modular Maven project. Project is deployed on Glassfish 3.1. Project (webapp) consists of three modules: Both WAR use heavy annotated (@Entity, @Inject, @EJB, ...) classes from Common. Currently Common is a JAR, but it's not a requirement. The question is: How to properly deploy such project? By my current (google and stackoverflow influenced) knowledge: Common cannot be a JAR, because .jar file is put into WEB-INF\lib directory inside JAR. This makes deploy-time initialization, because Glassfish expects .classes and produces an "Unsatisfied dependencies" error, resulting in failed deployment. Common cannot be a WAR, because with WAR overlay copying ocurrs after build -- resulting in build depending on itself... EDIT As Mike Decks comment suggests setup is ok, I assume supplying a full error message would be useful: What would that mean? What could be the cause? EDIT2 I'm enclosing relevant classes (trimmed a bit, i.e. not get/set methods, imports, etc.) and:
Problem was solved by adding empty 这篇关于使用Maven,如何根据J2EE / JPA JAR正确部署WAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! META-INF / beans.xml
和 META-INF / faces-config.xml
。空文件意味着默认配置,让Glassfish知道它应该寻找@Inject所需的类,而缺少它们则不会。
Deployment Error for module: User: Error occurred during deployment:
Exception while loading the app : WELD-001408 Unsatisfied dependencies
for type [Authentication] with qualifiers [@Default] at injection point
[[field] @Inject xxx.xxx.servlets.LoginFilter.authentication].
public class LoginFilter implements Filter {
@Inject
Authentication authentication;
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
LoginBean login = (LoginBean) httpRequest.getSession().getAttribute("loginBean");
if((login == null || !login.isAuthenticated())) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
String requestUrl = httpRequest.getRequestURI().toString();
authentication.setNavigateAfterLogin(requestUrl);
httpResponse.sendRedirect("./../login.html");
}
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig fConfig) throws ServletException {}
@Override
public void destroy() {}
}
@SessionScoped
public class Authentication implements Serializable {
@Inject
private UserDatabaseController userDb;
private ShopUser user;
private String navigateAfterLogin;
private String login;
private String password;
public boolean doLogin(String username, String password) {
List<ShopUser> users = userDb.getUsers();
for(ShopUser shopUser : users) {
if(shopUser.getLogin().equals(username) && shopUser.getPassword().equals(password)) {
setUser(shopUser);
return true;
}
}
return false;
}
public void doLogout() {
setUser(null);
}
public boolean isAuthenticated() {
return getUser() != null;
}
}
META-INF/beans.xml
and META-INF/faces-config.xml
. Empty files imply default configuration, among other things letting Glassfish know that it should look for classes needed for @Inject, while lack of them does not.