Where to put log4j.properties in a GWT web app - gwt

I have the log4j.properties and another .properties file under src and it works deployed in gwt dev mode. To build the war to launch to tomcat I use an ant script that compiles the .java classes and puts them in a JAR file. The JAR file gets copied into the WEB-INF folder in the war file.
The app runs fine when I don't use log4j but it can't find the properties file when I attempt to use log4j. All of the answers I see say WEB-INF/classes, but my project doesn't have a WEB-INF/classes directory, instead the JAR file that was copied to WEB-INF contains my projects classes.

You have to put log4j.properties (or log4j.xml) file into directory or JAR that is considered by your servlet-container as resource in Classpath.
So, simply create WEB-INF/classes directory and put it there, or pack it into your JAR.
See also Where should I put the log4j.properties file? - it could be useful.

Related

Exporting java projects in netbeans similar to eclipse

In eclipse, you can export a project as a jar file with the required libraries packaged in the same directory as the jar file in a separate folder. How exactly would I go about doing this in netbeans?
When using at. Right click on the project and select "Build" that will create a jar file in the dist directory of your project. If you have specified a main in your project that entry will be there in the manifest file, so you can easily use it a self-executing jar file.
All of the jar files that it depends on will be placed in the dist/lib directory of your project. If you are using your jar file as a self-executing jar file it is important that those files exist in a lib directory under the place where your jar file exists (i.e. their locations are recorded in the manifest file relative to the location of the jar). I know this is true when you use relative locations for your jars, but it may not be true if you've specified absolution locations.

Adding new jar in Netbeans project after building the project

I am developing a application in Netbeans7.1. I am facing one problem to add new jar file from the app after building the app.
As i know, when we build the project in Netbeans that will create a "jar" file and "lib" directory (which has all the libraries those are being used in the application) into the "dist" directory.
The problem is, I have to add new jar from my application into /lib/ directory after building the project. So that jar will be used in the application.
How should i do this?
If you have a successful build then it means the jar you wants to add is required at runtime not at compile time otherwise it wouldn't have compiled.
And if above is the case adding jar is straightforward.
Add the jar file to lib folder.
Now open you applications jar with some rar software like winrar.
Goto the META-INF folder open the MANIFEST.MF file and append the class path with lib/new_jar_file.jar.
Bingo..You are done.
Here is a screenshot of MAINIFEST.MF file and red box shows where to add the above mentioned lines.

JBoss jar library files

In JBoss, if you have an ear archive file, the way to tell the environment the place
of the lib folder, where it can find the library files, is the application.xml file.
Now I splitted the ear file into separate .war and .jar files. I do not have an ear folder anymore, so I deploy the war and jars directly in JBoss.
In the war archive I have the html and servlet files. In the jar archive I have the bean files. Now the library files are just needed by the java beans, not by the servlets.
So I need a folder in the .jar file to put the lib files and a way to tell the system the place of this folder.
If you want to have your jar libraries inside an ejb-jar: you can't, the standard specification doesn't allow you to have a jar inside another jar. Maybe some vendors provide specific solutions for that, but those are not standard. The standard solution would be to place all the related jars inside an ear. What you can do, and it's standard, is placing library jars inside the WEB-INF/lib directory of a war; but ejb-jar don't provide a similar structure.

Eclipse WebContent directory deployment in tomcat

In Eclipse, the folder structure when I create a Dynamic Web Project is
[srikanth#hana Sample]$ ls -R
.:
build src WebContent
./build:
classes
./build/classes:
./src:
./WebContent:
index.html META-INF scripts WEB-INF
./WebContent/META-INF:
MANIFEST.MF
./WebContent/scripts:
jquery-1.7.1.js
./WebContent/WEB-INF:
lib web.xml
./WebContent/WEB-INF/lib:
As you can see, there is this WebContent directory, When I copy the directory structure from Eclipse workspace and put in webapps directory of Tomcat, it didn't work. But, if I moved all the directories and files under WebContent directory a level above, it worked fine.
This is the folder structure in Tomcat's webapps directory under application:
[srikanth#hana Sample]$ ls -R
.:
build index.html META-INF scripts src WEB-INF
./build:
classes
./build/classes:
./META-INF:
MANIFEST.MF
./scripts:
jquery-1.7.1.js
./src:
./WEB-INF:
lib web.xml
./WEB-INF/lib:
So, now I can just go to http://localhost:8080/Sample and can go to index.html properly
What am I doing wrong? Why didn't it work just copying the application
from Eclipse to tomcat webapps directory directly? Why do I have to
change the directory structure?
I had the same problem, ./WebContent/index.html not appearing in the Eclipse-exported .war. This occurred on my new Eclipse system after I recreated a working project from my old system with Kepler Eclipse to a new system with Luna Eclipse.
I fixed this by going to Project / Properties / Deployment Assembly. I discovered that the old working system had this rule, while my new non-working systems was missing this rule ...
Source = /WebContent
Deploy Path = /
I corrected this on the new system by Pressing "Add..." and adding the missing rule.
Eclipse allows deploying the webapp directly to a server, without needing to copy anything by yourself. It also allows generating a deployable war file when you're ready to deploy to a test or production server.
Open the "Servers" view, right-click, and choose to create a new server. Once created, right-click on the server and choose to add your web-app into it. And then Eclipse will deploy your web-app to the server.
You're not supposed to manually copy anything from Eclipse. And if you need or want to do this, then you should probably use some ant script which generates the proper deployment structure. This structure is described in the servlet specification. It should have, under the root directory of the webapp, a WEB-INF directory containing:
classes: a directory containing your classes
lib: a directory containing all the jar files your app depends on
web.xml the webapp's deployment descriptor
All the other directories and files that are not under WEB-INF can be served by the web container.
When I copy the directory structure from Eclipse workspace and put in
webapps directory of Tomcat, it didn't work. But, if I moved all the
directories and files under WebContent directory a level above, it
worked fine
Not sure what you mean if I moved all the directories and files under WebContent directory a level above, it worked fine here and what you mean by saying a level above.
What you should be doing is not copy anything manually but right-click on the project and select Export as WAR option.
This will create a file named Project.war that contains the proper file structure i.e. WEB-INF etc that you are supposed to put under tomcat's webapps dir

Location of jsp class file inside war file

When I am creating a war file for struts2.xx project called 'test'. I want to know where my *.jsp are converted into *.class, can you tell me the exact location of jsp's class file inside my war file? Environment Should running in Tomcat7.xx
Jsp's generated class files wont go inside the war file. You can find them in the Servlet Containers directory (for tomcat it will be something like ${CATALINA_BASE}\work\Catalina\localhost\${WebAppName}\org\apache\jsp)