Re: How to create automatically packages from existing sources in
Eclipse
vigi98 wrote:
Hello,
I have a bunch of java files that are in different packages. To create
my project in Eclipse, I have imported everything by a drag and drop
from Windows Explorer to the default package of my project in Eclipse.
That is probably the worst way to create a project imaginable. You should not
use the unnamed package for anything. When importing a project into Eclipse,
you want to preserve the directory structure that reflects the package
structure of your app.
Web apps also have an overarching structure such as that recommended for
Tomcat, Java Blueprints, or other environments. Basically, web pages go in
the root of your web/ tree, deployment files in the WEB-INF/ subdirectory
under that. The Java classpath starts at WEB-INF/classes/, but that directory
doesn't exist in source, only in the deployment spaces.
Typical source organization:
projectroot/
|
|-- src/
| |-- com/
| | |-- lewscanon/
| : | |-- package/
| : : |-- app.java
|-- web/
| |-- index.jsp
| |
| |-- images/ ...
| |-- WEB-INF/
| | |
| : |-- web.xml
|
|-- build/ <= image of a deployed app
| |-- index.jsp
| |-- WEB-INF/
| | |-- web.xml
| : |-- classes/ <= .class tree starts here
|
|-- dist/
|-- app.war
How can I create automatically all the packages and move the sources
in theses packages ?
Explore the Eclipse File menu for "Import" options.
Btw, how can I compile this project, knowing the fact that there is
probably no main as these are classes for a JSP web site ?
Compilation is easy - you run 'javac' explicitly from the command line, or
implicitly from the command line via Ant, or implicitly from an IDE project.
In the case of a Web project, you also package the compiled code with the web
resources into a WAR (Web ARchive) file. Deploy the WAR to a server like
Tomcat and away you go.
Avoid code in web apps that explicitly writes to System.out or System.err.
--
Lew