WAR文件中缺少编译的类

编程入门 行业动态 更新时间:2024-10-26 11:23:51
本文介绍了WAR文件中缺少编译的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究一个简单的JSF 2应用程序,我遇到了托管bean的问题。我收到的错误是说找不到bean,当我查看战争时它没有任何已编译的bean。在我的pom.xml中,我有以下内容:

I'm working on a simple JSF 2 application and I'm having trouble with the managed beans. I was getting errors saying that the bean cannot be found and when I looked at the war it didn't have any compiled beans. In my pom.xml I had the following:

<project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.traintrack</groupId> <artifactId>test</artifactId> <version>SNAPSHOT</version> <packaging>war</packaging> <name>test</name> <build> <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory> <plugins> <plugin> <groupId>org.jboss.as.plugins</groupId> <artifactId>jboss-as-maven-plugin</artifactId> <version>7.7.Final</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build>

如果删除WebContent文件夹来自warSourceDirectory我在war文件中得到了我的项目的其余部分,但这似乎不对。该文件是由eclipse生成的,所以我认为它没问题。在WEB-INF中有一个类文件夹,它是空的。

If I remove the WebContent folder from the warSourceDirectory I get the rest of my project in the war file but this doesn't seem right. The file was generated by eclipse so I would assume it's ok. In WEB-INF there is a classes folder which is empty.

我的项目文件夹结构是:

My project folder structure is:

test - src/ - sample/ - sampleBean.java - WebContent/ - sample.xhtml - WEB-INF/ - faces-config.xml - web.xml - META-IF/

但是我编译的war文件的结构是这样的:

but my compiled war file's structure is like this:

test - sample.xhtml - WEB-INF/ - faces-config.xml - web.xml - classes/ - META-IF/

我的war文件中应包装什么以及编译的bean应该在哪里?

What should be packaged in my war file and where should the compiled bean be?

谢谢

推荐答案

您的问题是标准的Eclipse Web Tools不仅使用完全不同的目录布局Apache Maven用于Web应用程序,但也使用不同的方式指定库依赖项。解决此问题的最简单方法是更改​​项目以使用Maven约定并重新导入项目:

Your problem is that standard Eclipse Web Tools not only uses a completely different directory layout from that used by Apache Maven for web applications, but also uses a different way to specify library dependencies. The easiest way to fix this is to change your project to use the Maven conventions and re-import your project:

1. Move all of your main (not unit test) java source files into directory `src/main/java`; 2. Move all of your unit test java source files into directory `src/test/java`; 3. Move all the files in WebContent into directory `src/main/webapp` (excluding class files and jar files); 4. Remove the following from your pom.xml: a. `<outputDirectory>...</outputDirectory>`; b. `<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>`; 5. Delete the project from eclipse (but not the source files!); 6. Execute `mvn eclipse:clean` on your project from a command line; 7. Ensure that the .project file, .classpath file and content of .settings directory have been removed (manually if necessary); 8. Re-import the project into Eclipse as a 'Maven' project.

由于这是一个webapp,此时可能会出现编译错误,因为你的pom.xml文件似乎没有依赖关系。至少,您需要:

As this is a webapp, you will likely have compilation errors at this point as your pom.xml file appears to have no dependencies in it. At a minimum, you will need:

<dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> </dependencies>

最后,唯一的情况是你应该指定 maven-eclipse-你的pom.xml文件中的插件是你的Eclipse版本是否超过4年左右。此插件与现在内置到Eclipse中的Maven集成不兼容。使用的唯一安全目标是 eclipse:clean ,用于删除旧的eclipse项目配置。

Finally, the only circumstance in which you should specify the maven-eclipse-pluginin your pom.xml file is if your version of Eclipse is older than 4 years or so. This plugin is not compatible with the Maven integration that is now built into Eclipse. The only safe goal to use is eclipse:clean for deleting old eclipse project configuration.

更多推荐

WAR文件中缺少编译的类

本文发布于:2023-11-13 12:00:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   WAR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!