Replace content of property files when publishing application in Eclipse - java

We have an .ear project with several dependent .jar projects and we are using Maven. Each project has its own property file, but the properties inside do not have specific values but placeholders, e.g.
database.url=${database.url}
The placeholder ${database.url} is replaced during Maven build process using the resources plugin. So for each stage (local, test, integration, production) we have a different Maven profile defining the filter, so if we build for the test stage we get something like
database.url=url.for.test.db
The application is running on WLS 12, and we want to deploy it on local WLS using the Eclipse server plugin (we are using Eclipse Kepler). However, when we add the application to the server in Eclipse and publish, it is not working since the placeholders in the property files are not replaced with specific values.
AFAIK, the content being deployed is located in the Eclipse workspace:
<workspace>\.metadata\.plugins\org.eclipse.core.resources\.projects\<ear-project-name>\beadep\<WLS domain name>\<ear-project-name>
Of course we could change the property files in that location, but whenever we publish in Eclipse, those changes are overwritten and we get again the original property file
database.url=${database.url}
which is useless when it is deployed to WLS.
Is there any mechanism or possibility to change the property files before they are deployed to WLS from Eclipse?
Thanks for your help.

Ok here is the solution I chose to solve this (I am not sure whether it is the best one, but at least it is working):
I added a new folder to the .ear project named "properties-local". This folder contains only those property files which are relevant for local deployment (without placeholders), e.g.
database.url=url.for.local.db
Wihtin the properties of the Eclipse project, there is a section "Deployment Assembly". I added the new folder "properties-local" to the deploy path APP-INF/classes, so this is the place where they will appear in the .ear which is used for local deployment.
The maven-ear-plugin, which is responsible to build .ear files for remote stages, is not aware of the directory properties-local.
So the drawback of the solution is, there are now two folders with property files: one for local Eclipse deployment, one for .ear files which are deployed on remote servers.

Related

Deploying from intellij to local web logic

I am new to weblogic and have joined a team that has a number of projects. These projects have a master ant build that creates the associated ear, war, jar files and places them in a shared folder. This makes it handly to deploy to weblogic via the weblogic console. However, I have not found a way to make this process work with intellij's weblogic server integration.
I created a server instance in intellij and a run configuration that triggers the master build prior to running the weblogic server. I am not sure how to get the resources from this shared file and deploy them. Any guidance is greatly appreciated,
Ant build should not be used in local server deployment for weblogic. They just create deployable files.
In order to deploy the project to weblogic on IDEA, you must first create an artifact. Hit Ctrl+Shift+Alt+S(Project Structure Screen) and on the artifacts section, click "+" to create a new artifact. In the dropdown, you shuld see different kinds of deployable artifact types. Choose the appropriate type and it will create an artifact for you. If your configuration is correct, it should gather all the files needed in that artifact by itself. After that, you must go in the Run/Debug configuration screen for your local weblogic server and on the "Deployment" tab, choose the artifact you created.
Here
Run/Debug Configurations Screen:
Notice the "Before launch" section. You must see your newly created artifact there. If not, simply click "+" and choose your artifact.
Take a look: Packaging the application in a JAR
It explains a jar deployment, but the process is really the same. You just have to choose web application or JavaEE application. Remember;
choose JavaEE Application for ear packaging.
choose Web Application for war packaging.
Exploded means it will deploy the extracted content of the war/ear. You should stick with exploded.

usage and significance of .Classpath in Application EAR

I am currently working on an EAR application which has a WEB project and EJB project in it.
To work on eclipse with local set up i do so many build path setups and all.
All these buildpaths show up in .classpath of the project.
Now when i export the EAR and deploy on Server everything works on server.
My doubt is how does server know about my local system paths which are present in .classpath of my project.
Does it mean .classpath has no significance at runtime?
Please explain.
.classpath file is eclipse specific, it will not be bundled with the EAR. Eclipse uses it to set the classpath for the project.
An EAR has a well defined structure and Servlet container understands that structure, using it's knowledge it prods around in the EAR file and extracts classes to load in the runtime.
Obviously server doesn't have any knowledge of your local environment. An EAR (or WAR or JAR) file is a simple archive file (with some specification or the file order and all). You can unzip it using any utility (something like 7zip). Check the structure of the packed EAR, that will give you a better understanding of what goes to your server.

How To Add An External Folder With Configurations To A Web Application In Eclipse

I created a normal Dynamic Web Project in Eclipse. I added a folder to the project, which shows up after refreshing the project. The folder is containing an XML-file with configurations for the applications.
When I deploy the application on the tomcat in eclipse, the relative pathes do not match anymore. I need to copy the folder in the catalina home directory and then it works.
Question
How can I add the folder to my project, that when I start tomcat (V7) in eclipse the folder is deployed as well and the relative pathes work too?
When the development comes to an end, I will export a WAR-File and deploy it on my server. It would be great, if then the configurations will be included as well.
If you have any questions or you need some further information, do not hesitate to ask nor to comment!
In the project's properties I have found where I can add the folder when I export the WAR-file. But it doesn't deploy in eclipse's tomcat yet. This part is still remaining.
I copied the configs-folder into the WebContent-folder and accorded the paths.
Now i have two configurations, one for my local execution and one for the execution on Tomcat after the deployment.
Important Advise
I needed to accord the filepaths starting from CATALINA's home directory.

Java Dynamic web project classpath

I have a project which in the meantime runs locally on Tomcat but I'm planning to deploy to some server in the future.
I have a few questions:
I'm using tomcat-jdbc.jar. How should I include that jar in the project? copy it to WEB-INF/lib or add a library reference to tomcat? is the latter portable? Can I use this jar even if the server I'm deploying to is using jetty?
When I added the JRE, eclipse asked me to point it to the JRE path. The line that was added in the classpath was
classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"
How does eclipse figure out from this line where the JRE is at?
When the project is deployed to the server, how would the project hierarchy look like?
My guess is:
<project name>
----<build> (.class files)
----<WebContent>
--------<META-INF>
------------MANIFEST.MF
--------<WEB-INF>
------------<lib>
----------------external_jar.jar
------------web.xml
---------index.html
Is this correct? if so, how will the runtime know where to find the JRE? or the tomcat-jdbc.jar which is in the Tomcat installation folder?
Your application needs the following three types of "resources"
System Resources: JRE classes, some extensions/libraries provided by the server you deploy on.
Your dependencies: Any libraries you use, say common-utils, poi etc. These JAR files go in your web-inf/lib folder
Your classes. These are deployed with the WAR file at web-inf/classes
So, to answer your questions:
If you are deploying to Tomcat, the tomcat-jdbc.jar will be provided. Take care of the version though. If your prod server will be tomcat but dev is say Jetty, then you need to provide this jar in your local IDE, but not export it in the WAR file. But if you are developing on tomcat and say deploying on some other server, then this jar has to be bundled with your war file (web-inf/lib folder). Dev and Prod servers need not be same, but take care of the JRE version and dependency on Prod server provided libraries.
JRE is a configurable setting for your server and also your IDE (Eclipse)
Project hierarchy is correct, but you will most probably deploy as WAR file, so your build folder is exported in web-inf/classes. You can verify by opening the WAR file with any zip editor.
Regarding the portability of tomcat-jdbc.jar
Unfortunately this depends on the tomcat library and version. There might be more dependencies of this jar file which might cause problems later on. I would recommend not relying on this jar unless you plan to deploy on tomcat.
you should test your application with the same server you're going to use in production.
to see and set the jre properties eclipse->preferences->java->Installed JREs.
If you export a war file, all files in WebContent will be in the war and the .class files from src folder will be in WEB-INF/classes.
When you uses a server like tomcat, it uses the configuration you setted on it.
If you want the application to always reference your jar, put it in the web-inf lib.
As Daniel has mentioned below,eclipse gets the JREs from the installed JREs under the preferences tab. You can have multiple JREs installed and configured in your eclipse and then select individually for a project and also select default.
3.Your project hierarchy is correct. The runtime will get the JRE from the JAVA_HOME environment variable set on the server.
1) Pool connections, it's a service provided by Application Server (Tomcat in this case). IMHO you have to avoid bind your application with specific implementation, in that case use generic javax.sql.DataSource for expample, and then "inject" or lookup the implmementation from the server. Then if you use Jetty, configure what you want as connection pool implementation https://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource
So dont´t include in your web-inf/lib tomcat-jdbc.jar.
2) The "org.eclipse.jdt.launching.JRE_CONTAINER" it's a internal variable of eclipse and the value is what you configure on eclipse properties. It's used for eclipse to compile and run your app.
3) in your project structure ".class" files, must go in "WEB-INF/classes". That it's defined by servlet specification. Eclipse automatically generate the correct structure if you select yor project and with right click run "Export" --> "War file". Or you can use maven.

Java - Difference between dist and deploy folders

Forgive me for a novice question, but what is the difference between the dist and deploy folders? It seems like the same thing - both contains the .jar of the files. However, when you clean and build the project, it looks like only the dist folder is updated. How does the deploy folder get updated?
Thanks.
I will assume that you are using a directory layout similar to what Netbeans IDE creates by default.
dist is the folder where your generated archives are stored (so it gets updated through clean and build).
build folder contains compiled classes and resources, but not the compressed archives.
Maven, by default, places the content of both into a target folder.
A deploy folder is the place where you put your generated artifacts (either archives or directory trees with the same layout as archives, a.k.a. exploded archives) so that you Application Server can serve it.
In development environments it is not unusual to configure the server to scan the dist folders for generated artifacts and redeploy them. So, in that sense, deploy and dist folders can be the same.
You can even have "in place" deployment scenarios. This works by compiling your classes direct to WEB-INF/classes folder inside webapp (with something like Maven war:inplace goal). If you set your server to scan changes in this folder, you can edit resources such as jps in place and have it immediately reflected into your running application (a.k.a. exploded artifact hot deployment).
Of course that you can accomplish something similar by instructing your IDE to copy resources and compiled classes to a exploded archive structure and configuring your server to scan it. Netbeans tends to use build/web for that purpose.
Also sometimes incremental redeployment is not possible and frequently full redeploys are not desirable (some applications may take several minutes to redeploy). That is why you can use separate folders / deploy your artifacts as jars / wars / ears, etc.
Compiling, packaging and deploying are very different phases / concepts of a Build lifecycle, which may or may not happen together.
I hope this is enough info to get you going.
Cheers,
Typically a project is responsible for creating one artifact, when that artifact gets built it is put in a directory called target or dist. When your project is responsible for creating a web application, you need a place to layout the files in your project to run under your servlet container or app server, and that place is the deploy folder. So the dist directory would typically have a single artifact like a war, ear or jar, while the deploy folder would have the contents exploded in a directory structure where the app server can use them. How the deploy folder contents get updated depends on your build process or IDE integration.

Categories