I'm developing a Jboss web service that requires to access files which are in a folder of the project. When I deploy the web service, it creates a .jar, but the folder doesn't go inside of it, even if I added it to build path.
How do i tell jboss to place the folder inside of the .jar?
Thanks in advance.
I assume, because you explicitely say "jar" that your webservices are ejb endpoints, and not JAX-RPC servlet based webservices (because those would be packaged in a .war).
Unlike servlets, who are somewhat capable of finding files inside the project (as long as you can express their location as an offset to the web folder you can determine theire real location with ServletContext's getRealPath() EJB's don't have any "automatic" notion of directories.
So even if you could convince Eclipse to deploy files for you, I doubt it would help you much.
EDIT:
in a web-archive (.war) everything inside the web folder will be accessible by the servlets at runtime via the mechanism explained before. Do note however that files inside web are accessible via the web interface, except those inside the WEB-INF folder, so I'd suggest to at least store your files somewhere in a subdirectory of WEB-INF.
On a more global scale you should also ask yourself the question if you really must deploy these files with the application - and redeploy them with each redeployment. One solution in that case is to create some directory on the server (say c:/applicationfiles), create a JVM option e.g. -Dserverfilestore=c:/applicationfiles and have your application determine that directory with
String storebase=System.getProperty("serverfilestore");
The rest should be quite obvious. This solution will also work with you EJB services btw.
Related
I'm a .NET Programmer and right now I'm struggling with a web service I developed in JAVA. The web service doesn't have access to a database, only do some cryptographic tasks. To deploy it, I build the project with dependencies in Net Beans, generate a WAR File and upload it in the JBOSS web console.
The problem is that I'm looking for the analog of Web.Config in .Net, where some parameters can be set by a human without compiling again . In my code I call a XML file with all the parameters, however, the location of the file must be hardcoded. My solution was to set an enviornment variable with the folder so I always have to look for the XML there.
But I have an inconvenience: The same deploy will be set in two instances of JBOSS in the same server and both web services will have access to the same file, but that can't happen because some configurations are different in each one.
I tried the Web.xml file, but where can I find it in the JBOSS folder? Each time I upload the war or disable/enable it, it change the folder of the web.xml
What can you suggest?
The idea of using the web console is to work with artifacts (closed package) and you shouldn´t be manually modifying them.
From what i understood of your requirement, one option is to put an external file in the classpath of each jboss.
https://developer.jboss.org/wiki/HowToPutAnExternalFileInTheClasspath?_sscc=t
I have a web application which consist of JSP pages, Servlet and Consumes Web Services.
It also references apache axis and excel libraries.
Now I want to deploy my application directly in Weblogic server
How do i do that.Whcih archive shud i make WAR or JAR??
ALso how to ensures that it covers all the referenced libraries.
I have made my application in Jdeveloper, but I dont want to deploy it using Jdevelper..
I would package my solution as a .war file, containing all dependent .jar files.
That way your solution is self-contained. You can deploy to an app server containing other apps with their own versions of your libraries (dependent or developed). If you put the dependent jars directly into the app server (as you can do), then you're forcing those versions on all applications deployed, and that could well cause you grief.
The downside is that your developed .war file can become sizable. It's not normally a major problem, and I wouldn't worry about it until it's identified as an issue.
A JAR-file cannot contain a JAR-file, so that option is out. Since you mention JSPs and servlets a WAR would seem the appropriate option, although an EAR with a WAR and several JARs could also be a way forward...
Cheers,
Consider a WAR with your JAR files in WEB-INF/lib. Or, create an EAR with APP-INF/lib folder.
I wanted to add a .jsp file to an ear that is deployed at a client site. What would be the process for doing this? Keep in mind I'm very new to the java world. It's going to be a simple keepalive page that doesn't have to interact with other pages. It would be ideal to not have to recreate/redeploy the entire ear because there is stress involved in getting it back to the secured client site. We'd rather give the client instructions to add the page we send them into the ear they have. They can then redeploy it.
Thanks. If I missed any information let me know.
JSPs have to sit inside a WAR, which in turn sits inside the EAR. If you already have a WAR inside the EAR, then put it in that, or add another WAR with just the JSP inside. It can't sit directly in the EAR itself.
If rapid redeployment is what you need, then an EAR really isn't the best approach...
A JSP page is the source file that is compiled to a Java object by your application server. While deploying via an EAR or WAR is the traditional way, some servers, like Tomcat, can also deploy from an expanded EAR or WAR file. This is because EAR and WAR files actually just ZIP files, with a specific folder structure and information files in them.
You could always just try to send them the JSP page and simply have them copy and paste it into the deployment folder, overwriting the old file. Your application container should recognise that the source is newer than the compiled JSP page and recompile it for you on the fly when you refresh that page.
This works quite well in Tomcat - we often simply paste JSP files during development into the deployed application folder to test small changes.
Can anyone guide me how to get Servlets working in Apache Tomcat server? I can run the Servlets from Netbeans without problems, but I don't know where to put the class files in Tomcat.
In tomcat:
class files must be in TOMCAT_DIR/webapps/<yourAppName>/WEB-INF/classes
jar files must be in TOMCAT_DIR/webapps/<yourAppName>/WEB-INF/lib
(and if course you'll need web.xml in WEB-INF)
They go in Tomcat/webapps folder. There are several ways to deploy a JSP/Servlet webapplication on Tomcat. They are all described in Tomcat Web Application Deployment HOW-TO.
If you already have developed the webapplication in Netbeans, then Netbeans should already have build a WAR file of it in the /dist folder. You just need to drop the WAR file in Tomcat/webapps folder and Tomcat will automatically deploy it during startup (or even while running, this is called hotdeploy).
If you want to develop without an IDE and/or don't want to create a WAR, then you just need to put a folder representing the context name in Tomcat/webapps, e.g. Tomcat/webapps/contextname. It will become the public web content. You can drop all JSP files and other static files in there. Then, for classes you need to create a Tomcat/webapps/contextname/WEB-INF/classes folder. There should go the package structure.
If I make a spring mvc application, what are the things I have to do to deploy the application? (say its a commercial application)
What options do I have? Do all applications compress the classes into a .war file?
/WEB-INF/web.xml, appname-servlet.xml, etc.
/WEB-INF/jsp/*.*
/WEB-INF/appname.war ???
Done correctly, the build process will create a war which can be dropped into any servlet container (Tomcat, Jetty, Glassfish).
If you use external source files, those would have to be configured.
If you use advanced features provided by the servlet container, the server would have to configured as well.
Spring application is no different from any java web application when deploying. but generally the only thing I have to do is flip the order of test spring config with the actual one.
Any IDE could create the WAR file for you. As you've said the configuration xml files go to /WEB-INF folder and jsp files (by default) to /WEB-INF/jsp/. You also need to put all required jar files in /WEB-INF/lib folder. Compiled classes will go to /WEB-INF/classes, but let the IDE do that for you.
The war file shouldn't be in the /WEB-INF folder. In Tomcat for example you need to copy it to the webapps folder.