JSP在Openshift中导入Java类 [英] JSP importing java class in Openshift

查看:71
本文介绍了JSP在Openshift中导入Java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中创建了一个Java Web项目,并且效果很好(与jsp,servlet和Java类一起使用).现在,我正在尝试使其变得生动.我决定将其托管在提供自己文件结构的Openshift上.我已经尝试过将文件复制过来,并且大多数情况下都可以使用.

I made a java web project in Eclipse and it works great (with jsp, servlets, and java classes). Now I'm trying to make it live. I decided to host it on Openshift which provides its own file structure. I've tried copying my files over and it works for the most part.

问题是我的导入标签似乎不起作用,并且找不到我的类(例如,databaseInteractor,该类从我的数据库中获取要显示的信息).这可能是路径问题,但我不确定.

The problem is my import tags don't seem to work and it doesn't find my classes (such as databaseInteractor which fetches information from my database to be displayed). This might be a path issue but I'm not sure.

这是我在Eclipse中有效的状态:

This is what I had in Eclipse that was working:

<%@ page import ="java.util.ArrayList" %>
<%@ page import ="databaseInteractor.DatabaseInteractor" %>
<%@ page import ="databeseInteractor.House" %>

在Eclipse中,databaseInteractor包中同时包含了House.java和DatabaseInteractor.java类.但是在OpenShift中,我不明白什么是包.

In Eclipse I had both my classes House.java and DatabaseInteractor.java in the databaseInteractor package. But in OpenShift I don't understand what is the equivalent of a package.

我尝试了路径的各种迭代,并且得到的错误是:

I've tried various iterations of the path and errors I've gotten were:

  1. 仅可以导入类型. MyClasses.DatabaseInteractor解析为包 \(MyClasses是我在OpenShift中创建的文件夹)

  1. Only a type can be imported. MyClasses.DatabaseInteractor resolves to a package \(where MyClasses was a folder I made in OpenShift)

DatabaseInteractor无法解析为类型

DatabaseInteractor cannot be resolved to a type

正如您在下面看到的那样,出于调试目的,我已经在各处复制了DatabseInteractor.您会建议我在导入代码中尝试什么?

As you can see below, I've copied DatabseInteractor everywhere for purposes of debugging. What would you suggest I try in my import tags?

推荐答案

好吧,在进一步研究了您的问题之后,还有很多问题在发生. OpenShift上的软件包的工作方式与Java在其他任何地方使用的软件包完全相同.如果您的项目在本地运行,我很惊讶,这一定是由于具有类路径的Eclipse魔术所致.

Ok, after looking at your question more, there are lots of issues going on. Packages on OpenShift work exactly like packages do in Java anywhere else. If your project is working locally, i am surprised, it must be due to some Eclipse magic with class paths.

1.)所有.java文件都应该位于src/main/java目录中,这样它们才能被编译为类等(假设这是一个基于Maven的项目结构,看起来像这样).

1.) All .java files should be in your src/main/java directory, that way they get compiled into classes etc (assuming this is a maven based project structure, which it looks like it is).

2.)包中的任何Java类都应位于与该包相同名称的文件夹的INSIDE内,例如,databaseInteractor.DatabaseInteractor应该位于位置/src/main/java/databaseInteractor/DatabaseInteractor.java中,并且与任何其他类相同这是包装的一部分.

2.) Any java class that is in a package should be INSIDE of a folder that is named the same as the package, for instance, databaseInteractor.DatabaseInteractor should be in the location /src/main/java/databaseInteractor/DatabaseInteractor.java, the same with any other class that is part of a package.

3.)<%@ page import ="databeseInteractor.House" %>,数据库的拼写错误,这可能会导致某些问题.

3.) <%@ page import ="databeseInteractor.House" %>, database is spelled incorrectly, which may be causing some issues.

4.)另外,在那很难说,但是您的web.xml文件应位于WEB-INF文件夹内,而不应位于该"package"文件夹内. 我建议您研究如何在Java中使用程序包,并花一些时间研究使用Maven结构的Java Web项目.

4.) Also, it's hard to tell on there, but your web.xml file should be inside of the WEB-INF folder, but not inside of that "package" folder. I would suggest that you research how to use packages in Java, and also spend some time researching java web projects that use a Maven structure.

这篇关于JSP在Openshift中导入Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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