Pass parameters to WAR file deployed in two instances of JBOSS - java

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

Related

Modular jars/plugins within a Wildfly Web Application using ServiceLoaders

We extensively use Java ServiceLoaders as a plugin infrastructure for our application components. We define interfaces, and then use the loader to load them at run time. Adding additional jars with extensions and service files are fine for our use cases.
However, i'm struggling to understand how we would be able to continue this approach while deploying an application within Wildfly. The intent is as stated above, the ability to add "extension" jars to the web-application class path without having to
Stop the server
Unzip the war
Add additional jar
Zip war
Start the server
In Tomcat, we could deploy web application folders instead of a war. So stopping the server, dropping in a jar, and starting the server worked fine. Within Wildfly (latest), it appears to not like the deployment of a folder vs war.
I've read about the modules approach, but have not been successful using this approach to get the deployed application to see the module from the service loader implementations.
Would like to know if there is an alternative solution or perhaps we are doing something wrong?
Thanks
WildFly supports exploded deployments with the deployment scanner or using the explode command with jboss-cli. Using the jboss-cli you can even update files remotely.

Referring shared Java EE library for EAR application in weblogic

I have created a shared library with some jar files in weblogic server, now I have an EAR application and I want to use the class files from shared library in my web applications present in EAR application. So I have created weblogic-application.xml file inside my ear-app/META-INF/ directory and gave reference to shared library using below tags:
<library-ref>
<library-name>ebs_endeca_artifacts</library-name>
</library-ref>
But when I am trying to access the class files in my application, I am getting exception java.lang.ClassNotFoundException
Also it is required for me to refer to the shared library at ear level instead of declaring in weblogic.xml file of individual war files.
If I directly place the same jar files in my ear-app/APP-INF/lib directory instead of using shared library then my application is working fine without any issues.
Please help me how can I use the shared library in my ear application. I am using weblogic server 10.3.6
My shared library structure will be like this:
shared-web-app/WEB-INF/web.xml
shared-web-app/WEB-INF/lib/*.jar
You need the jars from the shared library in your classpath, because before you deploy the EAR, the application needs to be built. JDeveloper wouldn't know where are those classes stored, so that it need those at compile-time.
When preparing the application for deployment, you can create filters for the files that can be added within the WAR/EAR/<whatever>. Go to Application Properties -> Deployment and select your deployment profile. Click on the Edit button and a screen will be prompted, from where you can filter the files/libraries that can be included when the application is built.
If you don't include the shared library in the archive and have the fragment from the weblogic-application.xml you've posted, the WebLogic server will then use the classes from the shared library.
Hope that helps. Ask anything you don't understand as a comment. :)

How to Deploy Java EE Project which reference external JAR files in weblogic

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.

Deploying multiple war files with own JSF configurations

I'm using Maven to deploy a Java web project into my Tomcat 6.0 server. I have a "system" named project which is a war, and has his own JSF configuration and JSF managed beans.
The goal is that this system can have some apps installed on it, and apps themselves also have their web content and JSF configuration. My problem comes here, and I have two choices.
If I compile the app as a jar file, the faces-config.xml file has to be stored in the project's META-INF folder, so when loading the jar, JSF can find this file because it's located in the default place. However, my app also have web content, and I have to store it in the main system (webapp) location if I want it to be read. That's a functional but not elegant solution.
What I want to do is to define the app as a war file, and including it into the main system POM file, every web content from my app will be published in the server automatically. That's a good idea, but what can I do with my faces-config.xml file?? I already have one defined in my system and when Maven tries to deploy it, it finds there's already a same named file into the server. So I can't get my app JSF configuration from my system.
There is a way to define multiple jsf-config files, using a context-param in web.xml. Something like that works, but I want it to be dynamic:
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml, /WEB-INF/faces-managed-beans.xml,/WEB-INF/faces-navigation.xml</param-value>
</context-param>
Does anybody have any idea for that? Thanks in advance!
That's a good idea, but what can I do with my faces-config.xml file?? I already have one defined in my system ...
It sounds like you should remove that copy, and put a webapp specific copy in each webapp.

How to deploy to jboss a file folder into a jar?

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.

Categories