Archive

Archive for March, 2011

Search Results For: video streaming with java

March 24, 2011 Comments off

public class TimeClient
{
public static void main(String[] args) throws Exception
{
String host = “127.0.0.1”;
int port = 80;

ChannelFactory factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),Executors.newCachedThreadPool());
ClientBootstrap bootstrap = new ClientBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory()
{
public ChannelPipeline getPipeline()
{
return Channels.pipeline(new TimeEncoder(),new TimeClientHandler());
}
});
bootstrap.setOption(“tcpNoDelay”, true);
bootstrap.setOption(“keepAlive”, true);
bootstrap.connect(new InetSocketAddress(host, port));
}
}

Advertisements
Categories: Java

Maven Exception

March 23, 2011 Comments off

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:1.4:shade (default) on project sag-server: Error creating shaded jar: Invalid signature file digest for Manifest main attributes -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:1.4:shade (default) on project testProject: Error creating shaded jar: Invalid signature file digest for Manifest main attributes
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating shaded jar: Invalid signature file digest for Manifest main attributes
at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:503)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
… 19 more
Caused by: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:221)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:276)
at java.util.jar.JarVerifier.update(JarVerifier.java:188)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:325)
at java.util.jar.JarFile.getInputStream(JarFile.java:390)
at org.apache.maven.plugins.shade.DefaultShader.shade(DefaultShader.java:94)
at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:444)
… 21 more

Solution:

Step 1:go to pom.xml file

step 2:goto shade plugin part and add the below given lines

<filters>
<filter>
<artifact>*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/*.INF</exclude>
</excludes>
</filter>
</filters>
[/sourcecode=”xml”]

Categories: Maven

Find command in Linux with examples

March 21, 2011 Comments off

10 usage of find command in UNIX
find is very versatile command in UNIX and I used it a lot in my day to day work. I believe having knowledge of find command in UNIX and understanding of its different usage will increase your productivity a lot in UNIX. If your works involve lots of searching stuff or if you are a java or C++ programmer and your code resides in UNIX, find can greatly help you to look for any word inside your source file in the absence of an IDE, find is the alternative way of searching things in UNIX. grep is another command which provides similar functionality like find but in my opinion find is much more powerful than grep in unix.

This article is in continuation of my earlier article Top 10 basic networking Commands in Unix and Top 10 most useful CVS command in Unix .

Here I am listing down some of the way I use find command regularly, I hope this would help some one who is new in UNIX and find command or any developer who has started working on UNIX environment. this list is by no means complete and just some of my favorites , if you have something to share please share via commenting.

1) Running the last executed find command in Unix:
!find
This will repeat the last find command executed. It saves lot of time if you re searching for something and you need to execute same command again and again. In fact “!” can be used with any command to invoke previous run of that command.

2) Finding files which has been modified less than one day in Unix:
find . -mtime -1

This is my favorite while looking out some issue just to check which files have been modified recently which could be likely cause of  issue, believe me it helps a lot and many a times gives you enough hint of any problem due to intended or unintended file change.

3) List all the files and directories in the box which holds the 777 permission in Unix?
find . -perm 777 –print

I use this command to find out all the executable files , you can also modify it to find all the read only files or files having write permission etc by changing permissions e.g. to find all read only files in current directory : find . –perm 555
Here “.” or period denotes current directory. You can replace it with any directory you want.

4) How to do case insensitive search using find command in Unix? Use option “-i” with name, by default find searches are case sensitive.
find . –iname “error” –print

5) How to delete temporary files using find command in Unix?
find . -name *.tmp -print | xargs rm –f

Use of xargs along with find gives you immense power to do whatever you want with each search result. See another example below

6) How to find all text file which contains word Exception using find command in Unix ?
find . –name *.txt –print | xargs grep “Exception”

find . –name *.java –print | xargs grep “MemoryCache”, this will search all java files starting from current directory for word “MemoryCache”.

7) Finding files only in current directory not searching on sub directories:
While using find command I realized that some time I only need to find files and directories that are new , only in the current directory so I modified the find command as follows.

find . -maxdepth 1 -type f -newer first_file

Another way of doing it is below:

find . -type f -cmin 15 -prune

Means type file, last modified 15 minutes ago, only look at the current directory. (No sub-directories)

8) Find all files in current directory and subdirectory, greater than some size using find command in Unix:
find . -size +1000c -exec ls -l {} \;

Always use a c after the number, and specify the size in bytes, otherwise you will get confuse because find -size list files based on size of disk block. to find files using a range of file sizes, a minus or plus sign can be specified before the number. The minus sign means “less than,” and the plus sign means “greater than.” Suppose if you want to find all the files within a range you can use find command as below

find . -size +10000c -size -50000c -print

This example lists all files that are greater than 10,000 bytes, but less than 50,000 bytes:

9) Find files which are some days old and greater than some size in Unix. Very common scenario where you want to delete some large old files to free some space in your machine. You can use combination of “-mtime” and “-size” to achieve this.

find . -mtime +10 -size +50000c -exec ls -l {} \;

This command will find which are more than 10 days old and size greater than 50K.

10) You can use “awk” in combination of find to print a formatted output e.g. next command will find all of the symbolic links in your home directory, and print the files your symbolic links points to:

find . -type l -print | xargs ls -ld | awk ‘{print $10}’

“.” says starts from current directory and include all sub directory
“-type l” says list all links

Hope you find this useful , please share how you are using find commands and we can benefit from each others experience and work more efficiently in UNIX.

Categories: Linux/Unix

Sample Java Program

March 8, 2011 Comments off

Debugging maven web application with eclipse

March 3, 2011 Comments off

>

Recently I started a new JEE project using Maven2 as build tool, choice done du to the different services that it offers for project with a lot of modules and complex dependency ….
One of the problems that I faced is debugging web layer with respect to the directory structure of the default web archtype.

Here is the best method I found to solve this need:

I suppose that you already created a maven2 web project if not see :
http://maven.apache.org/guides/mini/guide-webapp.html

To run http web server I use jetty plugin by simply adding the jetty plugin to the pom.xml
http://jetty.mortbay.org/maven-plugin/howto.html

In order to validate this phase it’s possible de run the web app from the command line: mvn jetty:run and wating for maven to download the plugin and if successful running the application.

After that It’s time to configure eclipse for debugging the web app by selecting the Run > Debug … from the menu
# Set Main Class to “org.codehaus.classworlds.Launcher”

Go to the argument tab:
# Set Program arguments to “jetty6:run”
# Set VM arguments to “-Xmx512M -Dclassworlds.conf=[MAVEN_HOME]/bin/m2.conf -Dmaven.home=[MAVEN_HOME]”
(Replace MAVEN_HOME with the location of maven on your system)

Go to the classpath tab:
# remove the application from the user entries
# add the “[MAVEN_HOME]/core/boot/classworlds-1.1.jar” to the user entries

Go to the source tab:
# add the current project to debug

Now you can start debugging your application like you do it always

It is very interesting to set the –o option to the maven command in order to accelerate the fix/debug process.

Reference:
http://mahertb.blogspot.com/2006/08/debugging-maven-web-application-with.html

Categories: Maven
%d bloggers like this: