我应该将 html 和 java 文件放在 Apache Wicket 中的同一个包(文件夹)中吗?
我想知道是否有一个 html 文件和 java 文件驻留在不同文件夹中的示例。
I wonder if there is an example which html files and java files are resides in different folders.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不建议使用单独的页面目录,除非您对资源流的工作方式非常熟悉,而我则不然。
我见过的绝大多数 wicket 项目都将类和 html 文件保存在源目录中。 我尝试自己将它们分开,但后来发现获取其他资源(例如图像等)很麻烦; 所以,我最终将这些资源放在包目录中 - 最后我在几个不同的地方都有资源,这比将所有内容都放在包目录中更混乱。
也就是说,这是我用来将 html 模板放在单独文件夹中的代码。 应将其添加到应用程序类中的 Init() 中。
https://cwiki.apache。 org/confluence/display/WICKET/Control+where+HTML+files+are+loaded+from 有一个关于此的教程。
I don't recommend using a separate page directory unless you are quite comfortable with how resource streams work, which I am not.
The vast majority of wicket projects I have seen keep class and html files in the source directory. I tried separating them myself but then found that getting my hands on other resources, like images and such, was a hassle; so, I wound up putting those resources in the package directory - in the end I had resources in several different places and it was more of a mess than putting everything in package directory would have been.
That said, here's the code I used to put my html templates in a separate folder. It should be added to Init() in your application class.
https://cwiki.apache.org/confluence/display/WICKET/Control+where+HTML+files+are+loaded+from has a tutorial on this.
我使用 Maven(正如上面的用户指出的那样),通常将所有 .html 页面放在 src/main/resources/same/package/name/as/corresponding/java/file 中,
我发现这有效很好,因为我的设计师可以从资源文件夹中签出基础包,并且他们不会对所有 .java 文件感到困惑(更重要的是,他们不会意外更改它们!)
我做了一个 发布到邮件列表 如果您有兴趣。
I use Maven (as the user above points out) and typically put all my .html pages in
src/main/resources/same/package/name/as/corresponding/java/file
I find this works nicely as my designers can checkout the base package from the resources folder and they don't get confused by all the .java files (and more importantly they don't accidentally change them!)
I made a post to the mailing list if you are interested.
我不喜欢将 HTML 文件驻留在
src/main/resources
文件夹中。 我认为处理这个问题并在版本控制和项目中实现完全分离的最简单方法是使用 由 perilandmishap 链接的 Wicket 文章:因此,现在您的所有 HTML 文件都将位于新的、单独的 HTML 文件夹中,但仍与您的合并Java 类。 请记住,您仍然会在 HTML 文件夹中使用包命名方案,即 src/main/html/com/your/package
I'm not a fan of having the HTML files residing inside the
src/main/resources
folder. I think the simplest way to handle this and obtain a clean separation in version control and within your project is to use the last set up in the Wicket article linked by perilandmishap:So, now all your HTML files will be in the new, separate HTML folder but still merged with your Java classes. Just remember you would still use the package naming scheme within the HTML folder, i.e.
src/main/html/com/your/package
我对 java 和 html wicket 源文件使用单独的文件夹,但我的 ant 构建过程随后将 html 复制到我的 Web 应用程序的类文件夹中,这样我就避免了必须设置 wicket 资源设置的问题。
我的基本 build.properties
和编译/组装 ant 目标看起来像
I use seperate folders for my java and html wicket source files, but my ant build process then copies the html to the classes folder of my web app so i avoid issues of having to setup wicket resource settings.
My basic build.properties has
and the compile / assemble ant targets look like
这是使用 Maven 管理项目非常好的一个领域。 由于 Maven 在类路径中包含两个位置,因此您可以在逻辑上分离 Java 源代码和 HTML 文件,并且仍然让它们保持相同的包结构。 Java 代码进入 src/main/java,HTML 进入 src/main/resources。 构建或运行代码时,这两个位置都会添加到类路径中。
如果 Maven 不适合您,也许这个想法可以应用于您正在使用的任何环境。
This is one area where using Maven to manage your project is very nice. Since Maven has two locations that are included on the classpath, you can logically separate the Java source and the HTML files and still have them maintain the same package structure. The Java code goes into src/main/java and the HTML goes into src/main/resources. When building or running the code both of these locations are added to the classpath.
If Maven isn't for you perhaps this idea could be applied to whatever environment you are using.
我会将 Java 和 HTML 文件放在同一个文件夹中。 这将使选择与 Java 类相对应的 HTML 文件变得更加容易。 将组件 HTML 文件视为一种 UI 描述,否则将用 Java 编写(如 Swing)。
I would put Java and HTML files into the same folder. That would make it much more comfortable to pick the HTML file corresponding to a Java class. Think of a components HTML file as a sort of UI description that would otherwise be written in Java (like with Swing).