Shmoopy
Shmoopy

Reputation: 5534

Java Dynamic web project classpath

I have a project which in the meantime runs locally on Tomcat but I'm planning to deploy to some server in the future. I have a few questions:

  1. I'm using tomcat-jdbc.jar. How should I include that jar in the project? copy it to WEB-INF/lib or add a library reference to tomcat? is the latter portable? Can I use this jar even if the server I'm deploying to is using jetty?
  2. When I added the JRE, eclipse asked me to point it to the JRE path. The line that was added in the classpath was

classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"

How does eclipse figure out from this line where the JRE is at?

  1. When the project is deployed to the server, how would the project hierarchy look like?

My guess is:

<project name>
----<build> (.class files)
----<WebContent>
--------<META-INF>
------------MANIFEST.MF
--------<WEB-INF>
------------<lib>
----------------external_jar.jar
------------web.xml
---------index.html

Is this correct? if so, how will the runtime know where to find the JRE? or the tomcat-jdbc.jar which is in the Tomcat installation folder?

Upvotes: 2

Views: 3092

Answers (5)

Amit Suthar
Amit Suthar

Reputation: 1

my error is solved with this: i copied jar files on my clipboard and paste them in WEB-INF --->"lib" folder and reRun the project and you can change your browser

Upvotes: 0

Mart Dominguez
Mart Dominguez

Reputation: 163

1) Pool connections, it's a service provided by Application Server (Tomcat in this case). IMHO you have to avoid bind your application with specific implementation, in that case use generic javax.sql.DataSource for expample, and then "inject" or lookup the implmementation from the server. Then if you use Jetty, configure what you want as connection pool implementation https://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource

So dont´t include in your web-inf/lib tomcat-jdbc.jar.

2) The "org.eclipse.jdt.launching.JRE_CONTAINER" it's a internal variable of eclipse and the value is what you configure on eclipse properties. It's used for eclipse to compile and run your app.

3) in your project structure ".class" files, must go in "WEB-INF/classes". That it's defined by servlet specification. Eclipse automatically generate the correct structure if you select yor project and with right click run "Export" --> "War file". Or you can use maven.

Upvotes: 0

dubes
dubes

Reputation: 5524

Your application needs the following three types of "resources"

  1. System Resources: JRE classes, some extensions/libraries provided by the server you deploy on.
  2. Your dependencies: Any libraries you use, say common-utils, poi etc. These JAR files go in your web-inf/lib folder
  3. Your classes. These are deployed with the WAR file at web-inf/classes

So, to answer your questions:

  1. If you are deploying to Tomcat, the tomcat-jdbc.jar will be provided. Take care of the version though. If your prod server will be tomcat but dev is say Jetty, then you need to provide this jar in your local IDE, but not export it in the WAR file. But if you are developing on tomcat and say deploying on some other server, then this jar has to be bundled with your war file (web-inf/lib folder). Dev and Prod servers need not be same, but take care of the JRE version and dependency on Prod server provided libraries.
  2. JRE is a configurable setting for your server and also your IDE (Eclipse)
  3. Project hierarchy is correct, but you will most probably deploy as WAR file, so your build folder is exported in web-inf/classes. You can verify by opening the WAR file with any zip editor.

Regarding the portability of tomcat-jdbc.jar Unfortunately this depends on the tomcat library and version. There might be more dependencies of this jar file which might cause problems later on. I would recommend not relying on this jar unless you plan to deploy on tomcat.

Upvotes: 1

anand ojha
anand ojha

Reputation: 44

  1. If you want the application to always reference your jar, put it in the web-inf lib.
  2. As Daniel has mentioned below,eclipse gets the JREs from the installed JREs under the preferences tab. You can have multiple JREs installed and configured in your eclipse and then select individually for a project and also select default.

3.Your project hierarchy is correct. The runtime will get the JRE from the JAVA_HOME environment variable set on the server.

Upvotes: 0

Daniel Matsukuma
Daniel Matsukuma

Reputation: 41

  1. you should test your application with the same server you're going to use in production.
  2. to see and set the jre properties eclipse->preferences->java->Installed JREs.
  3. If you export a war file, all files in WebContent will be in the war and the .class files from src folder will be in WEB-INF/classes.

When you uses a server like tomcat, it uses the configuration you setted on it.

Upvotes: 0

Related Questions