These days, I drove crazy to deploy an ear on unix enviroment using Weblogic.
At the end I realized by using (cat -v file.properties) that such file was full of ^M at the end of the line.
This happened because I edited the properties file on Windows and I transfered to the production eviromnment by FileZilla.
By the usage of dos2unix command, I addressed the problem and the encoding of the file right now is correct.Because the properties file it's not the only one I edit, but I open the ear archive and customize the config.xml too, and then close the ear again and transfer it to linux, do you think that the encoding of that xml can be a problem even if it's embedded inside the ear ?
Thanks
You could remove the carriage return characters automatically with ants fixcrlf.
If you use maven you could also run an ant task to prepare the files.
Related
I'm kinda new to spring and web development as a whole.
My question is:
When you build a spring boot project (using Maven) into jar file and deploy it via Docker, everything is in one jar file. How can you access your resources (css, js, images, html...) if you want to edit something? Like change something in css file or add something to html page. Is it even possible? Or do you have to build a new jar file everytime, when you need to change something (in frontend)? Also, when there are being uploaded some images or other files, where are they stored? This stuff is very confusing for me and i can't find any related books or help at all.
Thanks for help!
when you package any java program it is nothing but a zip file. Based on what kind of package it is, you wither name it as a Jar or War.
Jar == Java archive
War == Web archive
Now, given the fact that jar and war both are essentially a zip archive, it gives you flexibility to extract and modify them just like any other zip file.
On windows, I think softwares like 7zip let you update the jar inline. I have done it multiple times, especially when I wanted to change application.properties alone on cloud machines, and no other code changes were required. In such cases, building the whole jar and transferring it again to cloud machine could be time consuming. So I would just extract the contents, update whatever I want to, and rezip the package.
Here is the commands you can use -
jar xf jar-file
This should extract the files into a directory.
This SO thread will guide you towards creating jar files.
Something like jar cf myJar.jar ** should be enough to generate a jar file IMO, but syntax might vary.
The jar file is actually just a zip file containing all the files and classes of your application, so technically you can change files in it like any other zip archive. Best practice is to build the jar file using Maven or Gradle from source every time you need something changed.
It's good practice to keep the source in version control using Git, and tag each build in the git repository - that way you can easily keep track of changes to the jar file by looking at what's in git at the time of the build.
I'm running Jetty 9.4.11.v20180605 as a Windows service with procrun. When I start this service Jetty extract the war into the temp folder. But when I shutdown the service Jetty doesn't delete these files on it's own.
To prevent the starting behaviour I changed the start.ini and set the jetty.deploy.extractWars to false. And it does what it should do but when I call the webapp I'm getting an HTTP ERROR 503 (Service Unavailable).
The second I've tried was to configure the WebAppContext in an xml file like this:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="persistTempDirectory">false</Set>
</Configure>
As described here, I wrote it in a file named jetty-web.xml, put it into the WEB-INF folder of my webapp and it works but when I call the webapp in the browser it just show me the folder structure of my webapp. The same happens when I put the line below into the jetty-web-cdi2.xml for server configuration instead.
What am I doing wrong?
From the documentation:
The /opt/jetty/temp directory is created as a durable place for Jetty to use for temp and working directories. Many Unix systems will periodically clean out the /tmp directory, this behavior is undesired in a Servlet container and has been known to cause problems. This durable directory at /opt/jetty/temp solves for that behavior.
There seem to be a lot of unit tests for jetty that include temp files, and some specifically for checking if temp files are deleted.
https://github.com/eclipse/jetty.project/blob/9706d70484863a014d3604e5e7cb4af40aa4cb1e/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/MultiPartServletTest.java#L135
Files can have the property to be deleted on exit
https://github.com/eclipse/jetty.project/blob/9706d70484863a014d3604e5e7cb4af40aa4cb1e/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java#L792
So to summarize, it seems as if Jetty needs long living temp files, and does it's best to clean them up after they are no longer needed.
Maybe jetty want to do so but in fact it doesn't in my case. A customer of mine restarts the server where the webapp runs on every night so jettys temp folder become quite large without any clearance. So I have to find a workaround for this and I have:
I use the Windows temp folder to let jetty unpack the war. You can get this user based directory by typing %TMP% into the command line.
This folder won't be cleared automatically by standard settings in Windows. But you can manually clear it by using the disk cleanup tool in Windows. In Windows 10 you can also enable the automatically cleanup of the temp folder: "Windows Settings" -> "System" -> "Storage" -> turn on "Storage sense".
If you clear the temp folder by the disk cleanup tool, the current used folder and properties file of jetty won't be touched, so the webapp is still working after the cleanup.
I am a sydadmin and was evaluating Hysterix Turbine.
https://github.com/Netflix/Turbine/wiki/Getting-Started-(1.x)
It is available as a war/jar file.
Directory structure looks like this after downloading
$ ls turbine-4.0
conf lib LICENSE NOTICE README.txt site sql turbine-4.0.jar
How to get this installed . If I download tomcat and put the above contents in deploy directory , will it work .
I am new to JAVA and Tomcat. So any help to get this installed will be highly appreciated.
Simple Steps-
Download the war file from here. If you are an absolute newbie, go with version 0.5. The version 0.0.1 has weird behaviour where it gives IOException while running multiple application instances on the same machine.
You should then deploy the war file to your tomcat by just placing it in the webapps folder in tomcat and starting the server. If your war name is turbine.war, you should be able to view your aggregated logs at http://localhost:8080/turbine/turbine.stream?cluster={cluster-name}
Before deploying your turbine.war, make sure you configure the file path of archaius.properties in catalina.sh in bin folder in the tomcat. Something like-
CATALINA_OPTS="-Darchaius.configurationSource.additionalUrls=file:///home/mukulbansal/Downloads/oauth-stuff/turbine-archaius.properties"
The contents of turbine-archaius.properties can something be like-
turbine.aggregator.clusterConfig={cluster-name}
turbine.instanceUrlSuffix.user-write=/hystrix.stream
turbine.ConfigPropertyBasedDiscovery.{cluster-name}.instances={IP:port-of-application-producing-hystrix-event-stream}
turbine.InstanceMonitor.eventStream.skipLineLogic.enabled=false
More info can be found here.
This question already has answers here:
Externalizing Tomcat webapp config from .war file
(4 answers)
Closed 7 years ago.
My application WAR has some settings baked in already. I would like to change them on fly before deploying in tomcat container. Right now I deploy them in /Catalina_base/, start the tomcat application, once WAR is uncompressed, I update conf file and restart tomcat. Any best practice to update conf file before starting tomcat ?
Also, how do I achieve this using chef cookbook?
Greatly appreciate your help.
As the comment from Chris Nauroth says, best practice is to keep environment-specific configuration out of the WAR.
However if you are stuck with the configuration being in that WAR, then you can use zip tools to update the configuration file.
If you are on a typical Linux distribution, then assuming your WAR file is called application.war and the configuration file you want to update is WEB-INF/classes/com/example/config.properties then you can run these commands during your deployment before you start Tomcat:
unzip application.war WEB-INF/classes/com/example/config.properties
# edit the configuration file now
zip -f -m application.war WEB-INF/classes/com/example/config.properties
After the unzip command, the file will be in a subfolder matching its location in the WAR (eg WEB-INF/classes/com/example/config.properties) and then the second zip command will delete it from the disk and put it back into the WAR.
I'm not familiar with Chef so I'm not sure how to run those commands automatically as part of the deployment, but presumably it provides a way to run command directly like this.
I have a very strange problem, that I can't figure out, the thing is that my aplication runs perfectly on the IDE (Eclipse), but not when exported, when I run the jar (double click) the aplication start but some functionality is missing (loading from a template file, but this does not happend when loading from a normal file), when I try to run it from console (java - jar my.jar) in order to see any error message it turns out that my aplication works perfectly fine! :S ...
Some more info:
My app is running over windows 7
I start the task manager, and I noticed that when I start my aplication using double click its under the name java.exe *32, and when I do it from command line its under the name java.exe (without "*32"), as far as I know I programmed nothing related to a 32 or 64 bits functionallity.
"Solved"
Well I was not able to solve it the way I wanted, as far as I was able to find, i found that there were a problem between the 2 java versions I was running x32 & x64, I deleted the 32 bit version and it start working as a charm, but I'm still not sure about what happend, I give my thanks to #Sajal Dutta one of its comments help me to understand part of the problem, thanks to all of you anyway, I'll keep searching until I find the problem...
When you create a jar from Eclipse, your assets don't get copied over to jar or location is not preserved. Open the jar and check if you have your templates in the right location or you have it at all.
To have the exported jar include your assets/resources-
Right click on your project in Eclipse. Then New -> Source Folder.
Name the source folder anything. e.g. template_src.
Copy or drag the entire directory of your template to template_src. Then make the jar.
Since it works via the command line but not when double-clicking the jar, it is likely that the working directory is different (and that you're loading the template with a relative path). When you run an executable jar by double-clicking, on some operating systems, the working directory is the home directory whereas when you run from the command line, it's the directory you're currently in.
The "files" in the jar are not handled by File, but are resources;
URL url = getClass().getResource("...");
InputStream in = getClass().getResourceAsStream("...");
Then, the file paths inside a jar, or on a non-Windows platform are case-sensitive.
"Template_A.xml"
is not
"template_a.xml"
Also you might inspect the jar with 7zip or WinZip.