Using tomcat without eclipse

I would like to use Tomcat without Eclipse.

I cannot find a Tomcat command line tutorial. They all use Eclipse.

What I need:

  • Create WAR file
  • Restart Tomcat with the new WAR file

  • Update WAR file (when I edit css / js file with Eclipse I don't need to update Tomcat)

Your best bet would be to use the command line. I am using Ubuntu.

Do you have any tips or resources to achieve this?

+3


source to share


3 answers


Just follow these steps:



  • Place the war file in the webapps tomcat directory

  • Restart tomcat by running scripts inside bin directory from your terminal ( shutdown.sh and startup.sh )

  • Run the app by launching a browser and then placing below url

     localhost:8080/app/index.jsp ( if generated app.war)
     localhost:8080/index.jsp (if you generated ROOT.war)
    
          

+2


source


Just to add what @ rai.shumar said, I also had to find this lately. Here's what I've learned so far.

Literature:

First create a dir structure:

  • Create an "example" to be your new project root.
  • create assembly
  • create assembly / class dir
  • create dist dir
  • create src dir
  • create WEB-INF file
  • create WEB-INF / lib dir

Then I added some test files (copying them from apache tomcat examples)

  • HelloMaster.java (renamed HelloWorldExample.java) to src /
  • LocalString * .properties for WEB-INF / classes
  • create empty build.xml file in "example" -dir
  • create empty web.xml file in WEB-INF directory

The project structure should look like this:



~/example$ tree .
├── build
│   └── classes
├── build.xml
├── dist
│   
├── src
│   └── HelloMaster.java
└── WEB-INF
    ├── classes
    │   ├── LocalStrings_en.properties
    │   ├── LocalStrings_es.properties
    │   ├── LocalStrings_fr.properties
    │   ├── LocalStrings.properties
    │   └── LocalStrings_pt.properties
    ├── lib
    └── web.xml

      

Then I added the following to the WEB-INF / web.xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">
  <servlet>
    <servlet-name>HelloMaster</servlet-name>
    <servlet-class>HelloMaster</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloMaster</servlet-name>
    <url-pattern>/hellomaster</url-pattern>
  </servlet-mapping>
</web-app>

      

build.xml is the one with the most meat:

<?xml version="1.0" ?> 
<project name="AntExample1" default="war">

  <!-- hack! setting classpath explicitly to tomcat classes -->
  <!-- export CLASSPATH=$CLASSPATH:/path_to_apache_tomcat_classes/classes/ -->  

  <path id="compile.classpath">
    <fileset dir="WEB-INF/lib">
      <include name="*.jar"/>
    </fileset>
  </path>

  <target name="init">
    <mkdir dir="build/classes"/>
    <mkdir dir="dist" />
  </target>

  <target name="compile" depends="init" >
    <javac destdir="build/classes" debug="true" srcdir="src">
      <classpath refid="compile.classpath"/>
    </javac>
  </target>

  <target name="war" depends="compile">
    <war destfile="dist/AntExample.war" webxml="WEB-INF/web.xml">
      <fileset dir=""/>
      <lib dir="WEB-INF/lib"/>
      <classes dir="build/classes"/>
    </war>
  </target>

  <target name="clean">
    <delete dir="dist" />
    <delete dir="build" />
  </target>  
</project>

      

Note. I don't know how to set the classpath without explicitly specifying it:

 > export CLASSPATH=$CLASSPATH:/path_to_apache_tomcat_classes/classes/    
 > ant  #-- this should create the war file in the dist dir

      

Then the war file should be named dist / AntExample.war and you can copy it to your webapps directory

+1


source


I am currently using tomcat without eclipse. I'm not sure if the IDE buys you a lot, other than coding the softer front ends. This is an opinion that not many can share. I'm not a web programmer expert either, I'm kind of a master of all trades.

Tips: First, always use your Linux distribution mechanisms and package management system to install / manage your software, in this case tomcat and its associated libraries. My dev block is Fedora 17, so some of what I'm doing is probably Fedora oriented.

Typically you make warfiles (like tar tar) and deploy them to a Java application server or container like tomcat. For servlets only, here is what I am doing in a batch script. Generally speaking, all of these servers have a common API and then some things that are proprietary. In theory, if you stick to general API properties, your servlet should run on most Java application servers.

  • Find the api you need to compile where foo.java is the POJO class used by your servlets: javac -cp / usr / share / java / tomcat6-servlet-api.jar foo.java servlet1.java servlet2.java

  • Move the compiled classes to your warfile creation location. cp * .class build / WEB-INF / classes /

It's a good idea for rm * .class before you create.

  • Change to that directory (usually call it string) and jar cvf myfoo.war * (see how to create web.xml file, there is a dir hierarchy defined there)

  • Expand your war file, what I am doing to help the hot deployment mechanism, rm -rf all old warfile and warfile cruftifoo and then I

sudo cp myfoo.war / var / lib / tomcat6 / webapps /

I am considering tomcat maintenance (start and stop) because hot deploy sometimes doesn't work.

0


source







All Articles