How can I make Tomcat interpret a jar library? - java

I'm working at a company that doesn't belong to the IT field, but its processes and data depend on a web application. My responsibility, as part of the IT team, is to update this application due to changes in the processes. The problem I have is that the former developers, that made this app with JAVA JDK 6, for some unknown reason, left a development environment on JBOSS and a production environment on Tomcat without the documentation to generate a war file on Tomcat.
Given this, I decided to substitute the .class and .xhtml files, which worked at the beginning. My problem is that one of my developments depends on the gson library, which JBOSS can interpret by copying the jar file to the server/default/lib, but when trying this same process with Tomcat (copying the jar file to lib folder from Tomcat or lib folder from the project), it doesn't work.
Could someone offer me an alternative so the project deployed on Tomcat identifies gson library?
Thanks beforehand for your help.

Putting in /WEB-INF/lib folder of the deployed webapp should work.
Restart your server after you add your jar.

Related

JAR libraries to TomCat

My servlet application uses JavaMail API and Java Activation Framework (JAF). I do development in IntelliJ IDE. TomCat runs on the same local Windows machine. When I try to run my Servlet from IntelliJ I have error related to fact TomCat not finds mentioned libraries. What is the right place to store libraries for TomCat? Is it possible ask IntelliJ to place required libraries to TomCat ?
Put the jar files in the WEB-INF/lib folder. If there isn't one, create one manually.
This way the jar files are added to the war file that gets created when you build your artifact, and tomcat knows where to find those jars at runtime.

Eclipse not loading WAR file

I received some java code and a WAR file for a web application that I need to test.
My overall goal is to be able to test the web application functionality and potentially make modifications to the code if need be.
I seem to be stuck on correctly loading this into eclipse.
I grabbed the WAR file and did a Import where I attempted to import the WAR file into a (Web -> WAR) project. The first issue was Eclipse was complaining there not being enough memory or the heap size. So I changed the java memory options in the eclipse.ini file. This seemed to resolve the complaining about the memory.
I restarted eclipse and attempted to import the Web - War again now it goes through the process of pretending like it is importing the war file but nothing happens after it finishes.
So overall my questions are
1 What is the correct process to load the war and source code into eclipse
2. Why is Eclipse not loading the war file
If you want to test a WAR file, you must deploy it to a Servlet container. Common Servlet containers include: Tomcat, Jetty, JBoss (which actually uses Tomcat), WebSphere, and WebLogic.
JBoss, WebSphere, and WebLogic are JEE environments, but they each have a Servlet container.
WAR file generally contains compiled version of .Java file i.e. .class file and other web related stuff.
You unzip the .war file with WinZip or similar software, if it contains source code attached, then only you can view or modify the code.ELSE you can do the below steps to run the application.
Install a server e.g Apache Tomcat to your PC.
Start the server from CMD.
Open the server home page.
Deploy your WAR file. Now you will be able to see the Application running.
If you want to modify the code then you should have .Java files inside your war file.

Is there a way to deploy a Maven project with "jar" packaging into Tomcat7?

My project generates a Jar as the output package and uses an external War file, available on our Artifactory, as the Web Application to be deployed on Tomcat (currently using version 7). This War file contains all libs and modules required for the application to run.
I have already packaged and ran those projects outside eclipse on a "vanilla" Tomcat installation. In this scenario, the Jar my project generates is loaded on the context.xml file this way:
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/igor/workspace/myapp/myapp-2.4.3.jar"/>
Is there a way I can deploy this project on Tomcat using Eclipse and still be able to debug it? Can I use the Jar generated for this purpose or do I have to deploy the workspace project?
As for the War file, do (or can) I have to add it as an dependency?
Thanks in advance!
EDIT
We actually provide an Web Framework, which is packaged as a war. Other applications that use that framework are exported as jars and loaded into the framework through the context file as cited above.
Your question is confusing probably because of your custom plugin/classloader and deployment which is sort of orthogonal to debugging.
What I recommend is you keep whatever system you have to build/package/deploy and use JVM remote debugging. That is do not use the Eclipse WTP since you seem to have custom steps for deployment but rather build your code deploy & run a separate Tomcat instance and then run the remote debugger in Eclipse.
You will get some hotcode swapping with this method but not as much as something like JRebel.. (which you could use also) it will certainly be better than constantly redeploying.

How to create a Debian package for my Java Web Application?

Kunagi is a simple Java Web application for which we are already creating a binary .deb package for our users. This package depends on tomcat6 and just puts the .war file into /var/lib/tomcat6/webapps. This works great on Debian and Ubuntu.
Now I want to create a real source package which can be integrated to Debian. Sadly I can not find any tutorial. There is a lot of fractioned information about tools like CDBS, DH7 or javahelper and their commands. But which one should I use?
I also have some conceptual questions:
Usualy, web applications are installed by copying the webapp into the webapps directory of the web container. Would it then be right to make my package dependent on tomcat6 and install my webapp directly into /var/lib/tomcat6/webapps? Or should my webapp be installed somewhere else, providing a separate Tomcat configuration and run with its own user, like other services do?
My webapp uses libraries (JARs) from other projects. Usualy these are placed in the WEB-INF/lib subdirectory of the webapp directory. Since including libraries in a package is not allowed in Debian, would it be right to add these projects as dependencies into my package and create symlinks in my WEB-INF/lib directory? Or how would I solve this problem?
My webapp needs to write files (application data). Since Tomcat is running as user www-data on Debian, the only directory where my webapp can write is /var/lib/tomcat6/webapps. Is it the right place to put my data? Or should my package create something like /var/lib/my-webapp-name/ and grant write permissions for user www-data?
Well... If you have to create Debian package than there is a great jdeb library which works for both ant and maven. The best feature is that it does not require any dpkg wrappers so your build will not be os-dependent.

Is there some easy way to execute code upon JBoss deployment of a JAR inside an EAR?

I plan to deploy an EAR packaged application into JBoss v4.2 as a folder containing the content of the EAR. Until now the EAR is deployed as a single file. I hope to be able to replace single JARs without the need to restart the application.
Is there any kind of event listener or annotation that can be used to register those JAR files upon deployment? The idea is a plugin like deployment of some features implementing a known interface. The plugins shall be used in a Seam webapp environment and may be exchanged with updated versions on the fly.
Any ideas? Thanks.
AFAIK, this is not possible/supported. When using an exploded EAR, touching an individual module would trigger the hot deployment of the whole EAR.
From Lightweight Java Web Application Development: Leveraging EJB3, JSF, POJO, and Seam:
3.4.2. Hot Deployment
Another JBoss feature that helps agile
development is exploded archives. The
EAR, EJB3 JAR and WAR files are not
necessarily JAR files in the JBoss
container. They can be directories
containing the contents of the JAR
file. For instance, instead of
deploying the dvdcatalog.ear file as a
single file, you can deploy it as
directory.
With the exploded directories, you can
make changes to any single JSP page or
Java class file in the application
while the server is running. Then you
can touch the META-INF/application.xml
file in the exploded directory (i.e.,
update the file's timestamp to
current) to re-deploy the entire EAR
application. This further saves
significant amount of time for rapid
turn-around agile developers.
What you're looking for doesn't sound simple. It would require detecting the change, unloading loaded class definitions coming from that JAR (assuming this information is known), reloading classes (something like that but I'm pretty sure I'm oversimplifying). Maybe more a job for an OSGI server.
See also
JBossClassLoadingUseCases
ClassLoadingConfiguration

Categories

Resources