Where's my server exceptions, Spring Data MongoDB?
mardi 12 janvier 2016
dimanche 28 juin 2015
Understand 'detached entity passed to persist' error with @ManyToMany JPA relation
In a JPA many to many relationship, if cascade type has been set at CascadeType.PERSIST (or CascadeType.ALL, which includes CascadeType.PERSIST), then while saving the parent and updating it with references of the child, it will try to save the child again.
Following issues can appear
@ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
Following issues can appear
- Child is already in persistence store (A detached instance has been passed) -in this case it will throw an exception “org.hibernate.PersistentObjectException: detached entity passed to persist”
- Child is a new entry, then it will be added in its table and operation will complete successfully
- If requirement is that Parent should add a existing but detached child(creating an instance with same ID and passing on from the client) -it needs to be reattached to session first. Hmm -for this there is NO way in JPA -Nope, merge does not reattach and entity. If you are using hibernate, you are lucky, merge can do the trick
For JPA, best option would be to query for entity on server side before trying to save it. - If its sure that only new child will be added, and not an detached instance from DB, CascadeType.PERSIST will take care of
- On the other hand, if requirement is never to add a new child if its not alredy in DB then CascadeType.PERSIST should be removed and cascade={CascadeType.MERGE,CascadeType.REFRESH} should be used
samedi 12 juillet 2014
Custom lazy loading indicator for ajax processing with WICKET APACHE
One of the things we must take care of when we use AJAX is to notify user when an AJAX request is already in progress. This is usually done displaying an animated picture as activity indicator while the AJAX request is running.
Wicket comes with a variant of components that display a default activity indicator during AJAX request processing.These components are respectively IndicatingAjaxButton, IndicatingAjaxLink and
IndicatingAjaxFallbackLink. you can check the official documentation for more details.
Here i will show you my prefered way of making ajax lazy loading indicator : first i want to make global ajax indicator that will be displayed when any component in that page make an ajax process, then i want to display a specific ajax indicator for specific component like submit button, of course with custom indicator picture and styling.
Global AJAX indicator
if you want to show an ajax indicator when any component in a page does an ajax process just make the wicket page implement the interface IAjaxIndicatorAware then override the method getAjaxIndicatorMarkupId(), this method should return the markup id of div panel which contain the custom loading picture.
JAVA code
public class pageWithAjaxProcess extends WebPage implements IAjaxIndicatorAware {
...
@Override
public String getAjaxIndicatorMarkupId() {
return "loadingIndicator_id";
}
....
HTML code
<div id="loadingIndicator_id" style="display:none;">
<img src="assets/lazyLoading.gif" width="48" height="48" alt="loading"/>
</div>
like this you can make your custom loading indicator, it is just a question of css styling.
Specific Ajax indicator
Sometimes we want to display a loading picture only for submit button which has a long processing time, so we can use IndicatingAjaxButton component and we override its getAjaxIndicatorMarkupId() method for customizing its loading panel.
vendredi 24 janvier 2014
Example syntax for Secure Copy (scp)
Example syntax for Secure Copy (scp)
What is Secure Copy?
scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.
Examples
Copy the file "foobar.txt" from a remote host to the local host
| $ scp your_username@remotehost.edu:foobar.txt /some/local/directory |
Copy the file "foobar.txt" from the local host to a remote host
| $ scp foobar.txt your_username@remotehost.edu:/some/remote/directory |
Copy the directory "foo" from the local host to a remote host's directory "bar"
| $ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar |
lundi 20 janvier 2014
How to Install Oracle Java JDK 6/7/8 on Ubuntu 13.04 / 12.10 / 12.04
In this article I will show you how to install the Oracle Java (JDK) 8, Oracle Java (JDK + JRE) 7 or Oracle Java (JDK) 6 on Ubuntu 13.04, Ubuntu 12.10 and Ubuntu 12.04.
The Oracla Java has been removed from the official Ubuntu repositories due to some Java licence issues.
Before you install it, remove OpenJDK, if you have it installed
$ sudo apt-get purge openjdk*
To install Java 8/7/6, do this:
In order not to get issues with the add-apt-repository command, install the following package:
$ sudo apt-get install software-properties-common
Add the PPA:
$ sudo add-apt-repository ppa:webupd8team/java
Update the repo index:
$ sudo add-apt-repository ppa:webupd8team/java
Update the repo index:
$ sudo apt-get update
install Java 8:
$ sudo apt-get install oracle-java8-installer
Or, install Java 7:
$ sudo apt-get install oracle-java7-installer
Or, install Java 6:
$ sudo apt-get install oracle-java6-installer
install Java 8:
$ sudo apt-get install oracle-java8-installer
Or, install Java 7:
$ sudo apt-get install oracle-java7-installer
Or, install Java 6:
$ sudo apt-get install oracle-java6-installer
mercredi 11 décembre 2013
How to add git remote repository on server
first you connect ssh to your server, then you can set up an empty repository for them by running git init with the --bare option, which initializes the repository without a working directory:
$ cd /var/www/GIT_REPOSITORY
$ mkdir newRemoteProject
$ cd newRemoteProject
$ git --bare init
then you should change the permission into this new remote repository
$chmod -R 777 /var/www/GIT_REPOSITORY/newRemoteProject$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin http://Server_Adresse/GIT_REPOSITORY/newRemoteProject
$ git push origin master
Note : the path to the remote repository is under /www because i have used gitweb with git over http.
For more informations, go to http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server
samedi 7 décembre 2013
How to disable JavaScript Validation from Eclipse Project ?
- Right click your project
- Select Properties -> JavaScript -> Include Path
- Select
Sourcetab. ( It looks identical to Java Build Path Source tab ) - Expand JavaScript source folder
- Highlight
Excludedpattern - Click
Editbutton - Click
Addbutton next toExclusion patternsbox. - You may either type Ant-style wildcard pattern, or click
Browsebutton to mention the JavaScript source by name.
The information about JavaScript source inclusion/exclusion is saved into .settings/.jsdtscope file. Do not forget to add it to your SCM.Here is how configuration looks with jquery files removed from validation
lundi 2 décembre 2013
Tuckey URL Rewrite
How can we make the web application URL cleaner and prettier instead of showing plenty of URL parameters? Is there a way for a simple easy solution to do that without configuring the application server like Tomcat? after spending a long time of research and test, i found a tool named Tuckey URL Rewrite that do exactly what i want.
My needs are the following, i have a java wicket web application with Tomcat 7 as webapp server and want to resolve two problems :
<rule>
My needs are the following, i have a java wicket web application with Tomcat 7 as webapp server and want to resolve two problems :
- First i would make pretty friend profile link as facebook or Google+, for example applicationName/Firstname.lastname ,
- Second, i want to implicitly add a dynamic parameter depending on the requested domain name for example : SuchCustomer.domineName.com should be implicitly transformed to SuchCustomer.domineName.com?CustomertName=SuchCustomer
STEP ONE :
install Tuckey URL Rewrite by adding Maven dependency :
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.3</version>
</dependency>
STEP TWO :
To WEB-INF/web.xml add :
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
STEP THREE :
Add urlrewrite.xml
in WEB-INF (src/main/webapp/WEB-INF/ for Maven users) , this file will contain all our rules. so to meet my needs, i write this two rules:
<rule>
<note>Clean Friend profile URL</note>
<from>^/([a-z0-9]+)\.([a-z0-9]{1,10})$</from>
<to>/FriendProfile?friendLoginID=$1</to>
</rule>
<rule>
<name>Add parameter to URL</name>
<condition name="host" operator="equal">SuchCustomer.DomainName.com</condition>
<from>^/$</from>
<to>?CustomerName=SuchCustomer</to>
</rule>
For more information about this tool, take a look at the official documentation.
mercredi 27 novembre 2013
Event based communication between wicket components
when we have a page structured with multiple panels, we need some times to update a component into a one panel following an event into another different panel in the same page, so how can we fix this type of scenario?
Starting from version 1.5 Wicket offers an event-based infrastructure for inter-component
communication. The infrastructure is based on two simple interfaces (both in package org.
apache.wicket.event) : IEventSource and IEventSink.
second interface must be implemented by those entities that want to receive a broadcast event.
The following entities already implement both these two interfaces (i.e. they can be either sender or
receiver): Component, Session, RequestCycle and Application.
IEventSource exposes a single method named send which takes in input three parameters:
Starting from version 1.5 Wicket offers an event-based infrastructure for inter-component
communication. The infrastructure is based on two simple interfaces (both in package org.
apache.wicket.event) : IEventSource and IEventSink.
FIRST sending an event:
The first interface must be implemented by those entities that want to broadcast en event while thesecond interface must be implemented by those entities that want to receive a broadcast event.
The following entities already implement both these two interfaces (i.e. they can be either sender or
receiver): Component, Session, RequestCycle and Application.
IEventSource exposes a single method named send which takes in input three parameters:
- sink: an implementation of IEventSink that will be the receiver of the event.
- broadcast: a Broadcast enum which defines the broadcast method used to dispatch the event to the sink and to other entities such as sink children, sink containers, session object,application object and the current request cycle. It has four possible values:
- BREADTH: The event is sent first to the specified sink and then to all its children components following a breadth-first order.
- DEPTH: The event is sent to the specified sink only after it has been dispatched to all its children components following a depth-first order.
- BUBBLE: The event is sent first to the specified sink and then to its parent containers.
- EXACT: The event is sent only to the specified sink.
- payload: a generic object representing the data sent with the event.
Each broadcast mode has its own traversal order for Session, RequestCycle and Application.
The below example shows an event sending. This method can be used from any other component:
First you need to create one class to encapsulate the notification and the AjaxRequestTarget and pass them using the events infrastructure.
private class Notification {
private String message;
private AjaxRequestTarget target;
... constructor, getters, setters...
}
send(getSession(), Broadcast.BREADTH, new Notification(message, target));
NEXT Receiving the event :
Interface IEventSink exposes callback method onEvent(IEvent<?> event) which is triggered
when a sink receives an event. The interface IEvent represents the received event and provides getter
methods to retrieve the event broadcast type, the source of the event and its payload. Typically the
received event is used checking the type of its payload object :
@Override
public void onEvent(IEvent event) {
if (event.getPayload() instanceof Notification) {
Notification notification = (Notification) event.getPayload();
... do whatever you want before updating the panel ...
// Update the panel
notification.getTarget().add(this);
}
}
You find in this link a project named InterComponetsEventsExample provides a concrete example of sending an event to a component (named 'container in the middle') using all the available broadcast methods:
dimanche 20 octobre 2013
How to load huge amount of data with Hibernate?
loading huge amount of data like more than one million of row can make a big problem, OutOfMemory Java error for example, so what can we do on such situation? with my little experience i can suggest two solutions, the first is the use of Criteria class and the second one is the ScrollableResults class.
- Criteria class :
with Creteria we can make pagination solution, this means that we split the result into differents pages to make it easy to load and process, see the code below :Criteria criteria = session.createCriteria(HistoryRecord.class); Criteria criteria = session.createCriteria(HistoryRecord.class).addOrder(Order.asc("CreatedDate") ); criteria.setMaxResults(10); criteria.setFirstResult(20); criteria.list();
these code let us take only 10 objects from index 20, even we have one million persisted objects into data base,we can avoid OutofMemory error. these code is not completed because it is static solution that take only object between 20 and 30 index. To be able to progressively load pages, setFirstResult() parametre should be dynamic because it represent the first index of the page, also this code should be called on demand. - ScrollableResults class
if you need to read each object separatly from a huge amout of data base objects instead of a complet page, you can use ScrollableResults class that make a iterator allows moving around within the results. See the below code :
Query query = session.createQuery(HistoryRecord.class); ScrollableResults results = query.scroll(); while (results.next()) { HistoryRecord obj = (HistoryRecord) results.get() // make some instructions ... } results.close();
Spring Bean Scopes Example
In Spring, bean scope is used to decide which type of bean instance should be return from Spring container back to the caller :
5 types of bean scopes supported :
5 types of bean scopes supported :
- singleton – Return a single bean instance per Spring IoC container
- prototype – Return a new bean instance each time when requested
- request – Return a single bean instance per HTTP request. *
- session – Return a single bean instance per HTTP session. *
- globalSession – Return a single bean instance per global HTTP session. *
In most cases, you may only deal with the Spring’s core scope – singleton and prototype, and the default scope is singleton.
P.S * means only valid in the context of a web-aware Spring ApplicationContext
for more informations, these notes were taken from : http://www.mkyong.com/spring/spring-bean-scopes-examples/
lundi 22 juillet 2013
There are no resources that can be added or removed from the server
Some time would like to deploy an ear file to WAS (Web Application Server) as usual. But Eclipse fail to find your EAR and it show an alert like this :
There are no resources that can be added or removed from the server
the solution is that your project needs to have a Eclipse Dynamic Web Module facet.
- right click on project and click properties
- Go to Project Facet and Select dynamic web module and click apply.
- go to tomcat and click add/remove
How to fix GC overhead limit exceeded in Eclipse
Eclipse will throw GC overhead limit exceeded error when it runs out of memory, normally while performing memory-consuming operations such as building workspace on big projects.
An internal error occurred during: "Building workspace". GC overhead limit exceeded
To fix this problem, you'll need to allocate more memory to your Eclipse instance. To do this, go to the Eclipse installation directory, and locate the eclipse.ini file.
To increase the memory allocation for your Eclipse instance, edit the number in the following lines accordingly.
To increase the memory allocation for your Eclipse instance, edit the number in the following lines accordingly.
-Xms1024m
-Xmx2048m
The number is the amount of memory, in Megabytes.You can also increase the value of MaxPermSize, as the following:
-XX:MaxPermSize=1024m
Restart Eclipse for the changes to take effect.
lundi 8 juillet 2013
Comment afficher une Valeur double avec 2 chiffres aprés la Virgule ?
La classe java.text.DecimalFormat permet de formater une valeur numérique dans le format de son choix en utilisant un pattern dont les symboles principaux sont les suivants :
- 0 permet de représenter un chiffre qui devra obligatoirement être présent, même s'il s'agit d'un zéro inutile.
- # permet de représenter un chiffre en ignorant les zéros inutiles.
- . (le point) permet de représenter le séparateur de la partie décimale.
- , (la virgule) permet de représenter le séparateur des groupes (milliers, millions, etc.).
(vous pouvez vous reporter à la documentation de la classe DecimalFormat pour obtenir la liste complète de tous les symboles).
| Format | 0 | 0,02 | 0,8 | 12,9 |
|---|---|---|---|---|
| # | 0 | 0 | 1 | 13 |
| ### | 0 | 0 | 1 | 13 |
| 0 | 0 | 0 | 1 | 13 |
| 000 | 000 | 000 | 001 | 013 |
| #.## | 0 | 0,02 | 0,8 | 12,9 |
| 0.## | 0 | 0,02 | 0,8 | 12,9 |
| 0.00 | 0,00 | 0,02 | 0,80 | 12,90 |
| #.00 | ,00 | ,02 | ,80 | 12,90 |
| #,##0.00 | 0,00 | 0,02 | 0,80 | 12,90 |
par exemple :
double ma_Valeur ;
DecimalFormat df = new DecimalFormat("#.##");
System.out.println(df.format(ma_Valeur));
mercredi 3 juillet 2013
Restore Deleted Files using Git
Sometime you can delete a file ,by accident, and then you commit your changes . after a while you recognize that you need this file So what you can do ??
what I have tried to resolve such problem (there are several ways) is this few steps :
- List all files that have been deleted from my git repository :
git log --diff-filter=D --summary
- Search the commit where you deleted your file
- undo your commit to the searched one BUT don't lose your modifications by taping this cmd :
git reset --soft HEAD~n
n: is the number of undo commit steps - if you type git status you will re-view your deleted file so to get the file back type this cmd :
git checkout -- [file name]
samedi 29 juin 2013
Change Wicket component behavior
Behaviors are kind of plug-ins for Components. They allow functionality to be added to a component and get essential events forwarded by the component. They can be bound to a concrete component (using the bind method which is called when the behavior is attached), but they don't need to. They can modify the components markup by changing the rendered ComponentTag. These are some of them :
- AbstractAjaxTimerBehavior
- AjaxEventBehavior
- AjaxFormComponentUpdatingBehavior
A behavior that generates an AJAX update callback at a regular interval. java doc
WicketComponenet.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(300)){
@Override
protected void onTimer(AjaxRequestTarget target) {
// TODO Auto-generated method stub
System.out.println("ajax here!");
target.add(ComponentToModify);
}});
An ajax behavior that is attached to a certain client-side (usually javascript) event, such as onClick, onChange, onKeyDown, etc. Example:
WebMarkupContainer div=new WebMarkupContainer(...);
div.setOutputMarkupId(true);
div.add(new AjaxEventBehavior("onclick") {
protected void onEvent(AjaxRequestTarget target) {
System.out.println("ajax here!");
}
}
This behavior will be linked to the onclick javascript event of the div WebMarkupContainer represents, and so anytime a user clicks this div the onEvent(AjaxRequestTarget) of the behavior is invoked.
Java doc
If you have a form component in wicket with some components and you want to change using ajax some things in that form before submit (when you click or edit on one of the components), then you have to use AjaxFormComponentUpdatingBehavior. This is a behavior that updates the hosting FormComponent via ajax when an event it is attached to is triggered.
WicketComponenet.add(new AjaxFormComponentUpdatingBehavior("onchange"){
@Override
protected void onUpdate(AjaxRequestTarget target){
// TODO
System.out.println("ajax here!");
target.add(ComponentToModify);
}}.setThrottleDelay(Duration.seconds(1))
);
ComponentToModify.setOutputMarkupId( true );
The key is that your component must be a FormComponent, otherwise the event won't be triggered. Simple components like CheckBox, TextField, DropDownChoice are all FormComponents. Java Doc you should be careful to set setOutputMarkupId(true) of the component that will be modified after defining the behavior !
mercredi 26 juin 2013
Jenkins getting Started
Jenkins Overview
Jenkins Continuous Integration (CI)
server was created to manage and control development lifecycle processes of all kinds, including build, document, test, package, static analysis and many more. Jenkins supports two main functions to help you improve code quality:
Ongoing building and testing
an easy-to-use continuous integration system, Jenkins lets you easily integrate changes to a software project and then automatically initiate a fresh build. By integrating changes as soon as they're ready, you'll find problems sooner, reduce integration conflicts and ensure you always have a working build.
Monitoring the execution of externally-run jobs
Jenkins schedules, monitors and manages externally-run jobs as well, such as cron jobs and procmail jobs and can even handle operations on a remote machine. The tool immediately informs you if something goes wrong, so you can fix the problem right away.
Built-in Automatic Backup
Jenkins lets you define regular backup schedules and control what to back up. Backups can be pushed to a remote server via SFTP or to a local file system. In this way, you configuration will be protected even in case of disaster like disk failures.
Self-upgrade
Upgrading Jenkins to a newer version is really easy. If you choose the native package (such as .deb or .rpm), your package manager will update it automatically. If you choose other installation methods, Jenkins will update itself with a click of a button from GUI.
Jenkins Jobs
in the table you find the list of existant jobs.
Create New Job
you have just to click to new job in the left and the folowing screen will appear.
next give a small description to your job :
Build New Job
After creating your job you can start your build by clicking on Start Build :
Job Configuration
The created jobs must be configured as follow :
Git Configuration
to use Jenkins you have to use a system version Control like Git or svn. If you are using an Http protocol to manage remote repository you need to specify the user credentials in the URL :
http://username:password@ci.opuntia360.com/....
Cron Configuration
the automation build is managed by the peridic Build option. This field follows the syntax of cron (with minor differences). Each line consists of 5 fields separated by TABs or spaces:
MINUTES HOURS JOURMOIS MONTH JOURSEMAINE MINUTES The minutes in an hour (0-59) HOURS The hours in a day (0-23) JOURMOIS the day in a month (1-31) MONTH The month (1-12) JOURSEMAINE The day of the week (0-7) where 0 and 7 are Sunday
for example I have so far used Periodic build in jenkins where the schedule:
*/2 * * * * builds the project every 2 minutes
Email Notification
Jenkins offer to you the oportunity to make a post build task.one of the import tasks is mail notification.
Smtp Config
it is very import to configure jenkins to know you smtp server.
Send Email After Build
click to create a post build step and choose "Editable Email Notification" and specify your mail adress.
UBUNTU: HOW TO CHANGE THE COMPUTER NAME (HOSTNAME)
Change Your Computer Name (Ubuntu)
You might run into a situation that requires you to change your (hostname) computer name, either because you need it to meet a naming scheme or you’re just bored with it and want something better. By following these steps, you’ll give your computer a new identity in no time.
- To get started, press Ctrl – Alt – T on your keyboard to open the Terminal. Next, type the command below to open the hostname file.
- Type this commande into the terminal and remember that the current computer name is @aymen-Aspire-E1-571
gksu gedit /etc/hostname
3. Then change the name to whatever you like and save the file.
4. Next, while command console is still open, type the command below to open the hosts file.
gksu gedit /etc/hosts
5. Finally, change the name shown to complete the change and save the file.
6. Close all open windows and restart your system.
After your system has restarted, it will have the new computer name.
Git Over Http
How To use the http protocol to manage git traffic ?
Traditionally git used to work only over ssh or git protocols while there was only a dumb version of git over http which was slow and inefficient.
While this was ok for most of the time sometimes git needs to be able to work over http.
Now starting from git 1.7 both git servers and clients have support for smart http which works over http(s) and is supposed to be as efficient as the ssh version.
the git-http-backend tool
This functionality is made available by a cgi script called git-http-backend provided with git-core.
So for git to work over http(s) there should be a web server already configured and as a result there won’t be any conflicts by both the web server and git trying acquire port 80.
So for git to work over http(s) there should be a web server already configured and as a result there won’t be any conflicts by both the web server and git trying acquire port 80.
Configuration
The following steps can be used to configure git to work over http(s) with Apache.
Apache Configuration
Make sure mod_cgi, mod_alias, and mod_env are enabled. to activate the WEBDAV module just use this command :
a2enmod dav_fs
1) Open the Apache config file
2) Append the following. Debian based system should have it under /etc/apache2/apache2.conf by default : SetEnv GIT_PROJECT_ROOT /home/user/git_pub SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
2) Append the following. Debian based system should have it under /etc/apache2/apache2.conf by default : SetEnv GIT_PROJECT_ROOT /home/user/git_pub SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
The GIT_PROJECT_ROOT should point to the root folder where git repositories would be hosted.
Set this away from the document root of the web server. What the above do is direct any requests with /git/ to the git-http-backend and tell the script that the root of git repositories is GIT_PROJECT_ROOT.
That is all that needs to be done that is specific to git over http(s). The manual for for the git-http-backend explains these steps pretty thoroughly. Now for some tit-bits that are not explained in the manual. Those who are experienced with Apache and Git would find the following very boring.
3) User Righs
For authentication for both read and write accesses append the following to the Apache config file /etc/apache2/apache2.conf :
That is all that needs to be done that is specific to git over http(s). The manual for for the git-http-backend explains these steps pretty thoroughly. Now for some tit-bits that are not explained in the manual. Those who are experienced with Apache and Git would find the following very boring.
3) User Righs
For authentication for both read and write accesses append the following to the Apache config file /etc/apache2/apache2.conf :
$ <Location /git>
$ AuthType Basic
$ AuthName “Private Git Access”
$ AuthUserFile /etc/apache2/authusers
$ Require valid-user
$ </Location>
What the above do is make requests to /git only accessible to valid users and tell valid users are listed on the file /etc/apache2/authusers. Make sure the file authusers is accessible by Apache. If there is no AuthUserFile in your system the following command can be used to create the user list at /etc/apache2/authusers and add the user ‘username’ to it. The command will prompt for a password for the user :
$ htpasswd -c /etc/apache2/authusers username
4) Restart Apache
On debian most probably :
$ sudo /etc/init.d/apache2 restart
Git Over Http Example
1) Create an empy bare git repository under the specified GIT_PROJECT_ROOT (/home/user/git_pub in our example) :
$ cd to GIT_PROJECT_ROOT
$ mkdir project
$ cd project
$ git init –bare
2) Make the folder ‘project’ and it’s children owned by the user which the web server is run from. This should be done for push requests by clients to work or otherwise the web server won’t be able to merge files.
On debian based systems this user is usually www-data and is defined in a file called envvars under apache2 installation :
On debian based systems this user is usually www-data and is defined in a file called envvars under apache2 installation :
$ sudo chown -R www-data project/
$ sudo chgrp -R www-data project/
Now the bare git repository should be pull-able and pushable by authorized users.
3) Clone the git repository over http(s) from another location:
$ git clone http://username@host/git/project
4) Do the first commit:
$ cd project
$ touch readme
$ git add readme
$ git commit -m “first commit”
$ git push origin master
How do I increase the permgen size of Tomcat Server ?
- Increase the Heap size from the catalina.sh file
Tomcat production server sometime will hit the following java.lang.OutOfMemoryError: PermGen space error.
java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
you should increase the memory by make change in catalina.sh.
Cataline.sh is located at \tomcat folder\bin\catalina.sh
Assign following line to JAVA_OPTS variable and add it into catalina.sh file.
export CATALINA_OPTS="-Xms512m -Xmx1024m" JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms2536m -Xmx2536m -XX:NewSize=256m -XX:MaxNewSize=1024m -XX:PermSize=1536m -XX:MaxPermSize=1536m -XX:+DisableExplicitGC"
- Increase the Heap size from the the Eclipse IDE
if you are using tomcat sever with eclipse you need to resolve this exception by modifying the tomcat arguments :
If you see
java.lang.OutOfMemoryError: PermGen space errors, you need to increase the permanent generation space available to Eclipse.
PermGen is the permanent generation of objects in the VM (Class names, internalized strings, objects that will never get garbage-collected). An easy, if somewhat memory-hungry fix is to enlarge the maximum space for these objects by adding
- double click on the tomcat server
- Click to Open Launch Configuration
- Choose the Arguments tab and add the following parameters
-Xms1024m -Xmx1024m -XX:PermSize=1024m -XX:MaxPermSize=1024m
- Be Careful !!!!
you have to be careful when increasing the heap size of your tomcat server and jvm.
As you can see, if you allocate a large Java Heap (2 GB+) for a 32-bit JVM process, the native memory space capacity will be reduced automatically, opening the door for JVM native memory allocation failures.
you will get the following exception :OutOfMemoryError: unable to create new native thread
For a 64-bit JVM process, your main concern, from a JVM C-Heap perspective, is the capacity and availability of the OS physical, virtual and swap memory.
What you will learn shortly is that this JVM problem is very often related to native memory depletion; either at the JVM process or OS level. For now please keep in mind that:
- A 32-bit JVM process is in theory allowed to grow up to 4 GB (even much lower on some older 32-bit Windows versions).
- For a 32-bit JVM process, the C-Heap is in a race with the Java Heap and PermGen space e.g. C-Heap capacity = 2-4 GB – Java Heap size (-Xms, -Xmx) – PermGen size (-XX:MaxPermSize)
- A 64-bit JVM process is in theory allowed to use most of the OS virtual memory available or up to 16 EB (16 million TB)
Inscription à :
Articles (Atom)














