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

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.

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.

How can I make Tomcat interpret a jar library?

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.

what is the need of Servlet.jar in eclipseIDE when we create a servlet in Dynamic Web Project using Build Path option?

I was going through java tutorials and found that after creating the servlet they have added the servlet.jar file using build path opt. But in my case servlet is still working without that external jar file.
So what is the need of that external jar file?
It's still working fine in your case because
Just check below
Right click on your project then go to Properties -> Targeted Runtime -> Apache tomcat
If you have selected that checkbox you no need to add servlet jar and if it's not then you need to add servlet jar in lib folder
So in your case you must have selected targeted runtime that's why even though u have not added servlet jar file it's working fine
You don't need to add because you may have added Apache Tomcat as server run time in for your web project and Apache tomcat has servlet.jar in its lib folder so it will be there
you can check it by going in Apache tomcat folder > lib
You need Servlet-api.jar to compile servlets in eclipse but while deploying servlet container ( like tomcat ) will have it built in. Infact it is bad practise to include it inside your WEB-INF/LIB folder.If you configure your eclipse to use libraries from tomcat(or other servlet containers) then you might not need it manually.
Servlet-api.jar is by default provided by the container environment. So you should not put it in your WEB-INF/LIB folder when you are deploying your application. However, it is required for compiling your Servlets. In case if you are using Eclipse as your IDE, place it in your classpath using Add External JAR files option.
Ensure that you're using at least Eclipse IDE for Java EE developers (with the EE). It contains development tools to create dynamic web projects and easily integrate servletcontainers (those tools are part of Web Tools Platform, WTP). You also need to ensure that you already have a servletcontainer installed which implements at least the same Servlet API version as the servletcontainer in the production environment, for example Apache Tomcat, Oracle GlassFish, JBoss AS/WildFly, etc.
You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries like servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc. It would only lead to future portability, compatibility, classpath and maintainability troubles, because your webapp would not work when it's deployed to a servletcontainer of a different make/version than where those libraries are originally obtained from.
These links below will give you more information about this
How do I import the javax.servlet API in my Eclipse project?
Understanding who provides servlet-api.jar, is it web-container or part of Java EE download
http://wiki.metawerx.net/wiki/JARFilesYouShouldNeverIncludeInYourWebapp

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.

Modifying Java Paths when deploying WAR

I have a webserver that I developed in Eclipse with a local TomCat server. When developing, I often had to run scripts from the command line from my Java code. I just looked at the working directory that Java inside eclipse was working from (was in the Eclipse subdirectory somewhere) and put a ton of files and scripts in here.
Now when creating a WAR those paths are wrong. I'm just not sure how to integrate this all into my project correctly. Should I copy everything into the Eclipse project directory and make the Java 'home' path here - how can I set this up so that the WAR would work when deployed on a webserver?
Should I copy everything into the Eclipse project directory and make the Java 'home' path here - how can I set this up so that the WAR would work when deployed on a webserver?
That is a bad idea:
Since you can't change the "current directory" in a Java program, the only way to do that would be to "cd" to the Eclipse project directory and start Tomcat from there. Yuck!!
And that's conceptually wrong:
Suppose you had two WAR files created in two distinct Eclipse projects. An application cannot have two different "current" directories. It makes no sense.
What if you want to deploy to a Tomcat on a system that doesn't have the Eclipse projector available to it ...
The correct way to solve this is to put all of the requisite files into the WAR file, and then access them from your webapp codebase using either webapp relative file paths ... or via the classpath.
Yes, it will entail changing the code of your webapp, but it is the right approach.

Categories

Resources