?
Solved

Adding JAR file versus Adding both JAR and Java EE Module Dependency

Posted on 2009-05-13
8
Medium Priority
?
1,390 Views
Last Modified: 2013-12-15
I have a simple Java Web Module project. This project has an index.html which has a form where one can enter a number. This form when submitted leads the flow to a servlet in the project which displays the double of that number.

There is also a JAR file in build path, a JAR of a Simple Java Project  which has two classes each of which having one function returning an integer.

Question: I know to access functionality of that Simple Java Project, I need its JAR in build path. My Web Project is working fine now. However some hours back it was not. It did not show any compile time error but when time came for the servlet to run from module, it gave a 500 error. It was mitigated only if I retained the JAR in build path and added the Simple Java Project  j2 to Java EE Module Dependencies. Why did I have to add the project when its JAR was already there?

Am I right in saying only adding the JAR file is enough to access the two classes in Simple Java Project or do I need to add that  Simple Java Project in EE Module Dependency as well?

However, some hours later, this web module is running fine without me adding Simple Java Project j2 to Java EE Module Dependencies.
1). Simple Java Project :  j2
 
a).  public class class1 {    int class1_function() {  return 1000; }   }
 
b).   public class class2 {   int class2_function(){  return 2000;  }    }
 
2).Web Module Project: p2
 
a).Servlet s1:
 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
 
 
public class s1 extends HttpServlet {
 
public void init (ServletConfig config) throws ServletException {super.init (config);}
 
 
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String number=null;
class1 c1=new class1();
class2 c2=new class2();
int i;
 
response.setContentType ("text/html");
PrintWriter out = response.getWriter ();
out.println ("<html>");
out.println ("<body>");
number=request.getParameter ("text1");
i=Integer.valueOf(number);
 
out.println("<br><br><h1> The double of the entered number is:    "+ (i*2)+ "</h1>");
out.println ("<br> Total of the ints from two classes: "+(c1.class1_function()+c2.class2_function())+"<br>");
out.println("</body>");
out.println("</html>");
out.close();
}
} 
 
b). Form index.html
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="s1" >
<br>
 
Input a number please:
 
<input type= "text" name= "text1" >  </input>
 
<center><input type="submit"/></center>
</form>
</body>
 
</html>

Open in new window

Error-500.jpg
Working-fine.jpg
EE-Dependency-Screen.jpg
0
Comment
Question by:perfect_tranquility
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 2

Accepted Solution

by:
filosof earned 2000 total points
ID: 24382803
When you use Java EE plug-ins in Eclipse you need to specify Java EE module dependencies. Java build path is used by Eclipse's compiler and also can be used in classpath of launch configurations which are run from Eclipse. In case of Web Application things are little different. Eclipse starts the Tomcat or any other server and deploys files to this server (builds, packs into war and copies it to some folder). Very often the build path for building projects and for deployment (jar which must be copied to the server's folder) differ. For example assume that your server runtime already contains some libraries.
So, when you specify EE module dependencies yiou say to the deployer which files must be copied to the destination.
As regard to your experiment that after a while your project run without module dependencies. Maybe jar was cached in the target folder. You can better understand all this mechanism when you find the folder to which Eclipse copies the deployed files, usually this folder is in workspace in folder .metadata.
This path is also present in conseole when you run Tomcat - see the header of console - it writes a path to the context.
0
 
LVL 2

Expert Comment

by:filosof
ID: 24382827
PS for finding the path to the deployment folder try investigating the console or launch configurations. this path is written somewhere . i dont remember where:) it will be hard to find in folder .metadata because it contains tons of trash
0
 

Author Comment

by:perfect_tranquility
ID: 24385802
filesof: thank you so much for replying fast. just one last query:

You said :"When you use Java EE plug-ins in Eclipse you need to specify Java EE module dependencies"

Did you mean plug in for application servers and Servlet Containers like Tomcat?  I installed both of those and then added them under Servers in Eclipse Ganymede.

Thanks

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:perfect_tranquility
ID: 24386003
Also what you said about the cache looks highly possible, I re-ran that application again deleting the EE dependencies. It again gave me an error 500, but once I added those and ran the application, then the application ran fine everytime irrespective of whether I had EE dependencies specified or not, That looks like cache behavior.

As reagrds thr path to the deployment folder, I assume it should be in the "workspace" folder.
I can see the workspace location by going to File--> Switch WorkSpace

I can see all the projects there in that folder  in "workspace" folder.  I checked .metadata as I did not find anything that might interest me,lol

I went straight to my project folder t1 and under that straight to .classpath. It does mention the jar file under <classpath>, second entry from bottom. Please see snap of .classpath file

So all in all, I saw that though if i just add JAR file to build path, it resolves compile time issue but it will not resolve the issues at run time for which I need to use the EE dependecies.

1). Is there a way to clear the cache of old junk and make sure the Servlet Container culls in fresh data every time?

2).Also if If I do stuff the old way and do not add servers and Servlet Containers to Eclipse, would I still need EE dependencies to be specified?

Thanks !!!

Roopesh

0
 

Author Comment

by:perfect_tranquility
ID: 24386029
I apologize, forgot to add the snapshot of the .classpath.

Please find it here.

R
classpath.txt
0
 

Author Comment

by:perfect_tranquility
ID: 24386350
While I wait for your response here, I am opening a new question under Apache Tomcat and Eclipse forum, please watch out.

It is also related to something you helped me with above but thought it only proper to put as a separate question due to what I thought about it.

Thanks
0
 
LVL 2

Expert Comment

by:filosof
ID: 24388685
When you launched the Tomcat server from Eclipse, you can go to the list of launch configurations and see the launch configuration for Tomcat. On the tab arguments you will find something as in the attached code piece. See the corresponding paths, you will find how the deployment folders look like.

You can edit content of these folder manually.
-Dcatalina.base="D:\Work\XXXX\Development\Eclipse_Ganymede\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0" -Dcatalina.home="C:\Program Files\Apache Software Foundation\Tomcat 5.5" -Dwtp.deploy="D:\Work\XXXX\Development\Eclipse_Ganymede\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps" -Djava.endorsed.dirs="C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\endorsed"

Open in new window

0
 

Author Closing Comment

by:perfect_tranquility
ID: 31581315
Thank you very much, Sir for your timely help, Did you check my other question. It is in Apche Tomcat forum and secondarily, Eclipse.

Regards

Roopesh
0

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question