JSP importing java class in Openshift

℡╲_俬逩灬. 提交于 2019-12-13 07:50:42

问题


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.

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.

This is what I had in Eclipse that was working:

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

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. Only a type can be imported. MyClasses.DatabaseInteractor resolves to a package \(where MyClasses was a folder I made in OpenShift)

  2. DatabaseInteractor cannot be resolved to a type

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


回答1:


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.) 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.) 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" %>, database is spelled incorrectly, which may be causing some issues.

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.



来源:https://stackoverflow.com/questions/29108936/jsp-importing-java-class-in-openshift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!