Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, July 1, 2013

remote debug a locally hosted tomcat instance on intellij

tomcat:
open tomcat's service manager and go into the java tab

configure jdwp to use intellij settings. this will enable intellij to publish artifacts into tomcat make sure each directive is in its own line

-Xdebug
-Xrunjdwp:transport=dt_socket,address=54312,suspend=n,server=y
-javaagent:C:\Users\uye\.IntelliJIdea12\system\groovyHotSwap\gragent.jar

configure rmi and debugging
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=fxdms-hp

intellij:
create a new remote tomcat server
under the server tab, configure and pick tomcat's binaries
set jmx port to 1099
set remote staging>type to Same file system
under remote connection settings set host to localhost and port to 8080

Friday, February 10, 2012

naming conventions

nouns in all caps will be treated as ordinary words, including abbreviations and is subject to camel caps rules

e.g.
UUID => Uuid
DAO => Dao


Dao should also follow these rules, even in
* ClassNamesDao
* fieldNameDao
* bean id="nameDao"

- the word "name" is to be treated as a suffix, and not as a separate word
-- filename, username, firstname, lastname

Monday, February 6, 2012

force eclipse to recognize war maven projects

run maven command
mvn -Dwtpversion=2.0 compile eclipse:eclipse

then refresh the project

Wednesday, January 9, 2008

running executable jar files via console

Use when:
1. NoClassDefFoundError and MissingResourceExceptions keep appearing every time an executable jar file is run
2. executable jar files need 3rd party libraries
3. resource folders need to be accessible via classpath


There are two ways to run executable jar files. Which to use depends on how the jar file was constructed.

If the jar file does not need any 3rd party libraries use:

java -jar <jarfile>


If the jar file uses any 3rd party libraries that has not been put inside the archive or needs to have folders accessible via classpath, use:

java -cp .;<libraries>;<classpath>;<jarfile> <main-class>

*Note that a folder containing customized Properties files must appear before the main jar file to override any copies inside the archive itself


Monday, January 7, 2008

simple properties file management

Use when:
1. a majority of classes have to each load its own set of settings.
2. properties file is located in folder outside the default classpath
3. a generic solution is needed for loading configuration files that are independent of the filesystem


==========

  1. create a new Class and have it named "ResourceManager"
  2. turn the class into a singleton by hiding the constructor and give it a method named getInstance() that returns an instance of the class
  3. create a static method that will handle file loading. name this method "getResource()" and have it accept a Class object named "name" as a parameter and have it return a Properties object
  4. pass the "name" object appended with ".properties" to the ClassLoader.getResourceAsStream() method to load a Properties file as an InputStream
  5. create a new Properties object and call its "load()" method using the InputStream from step 4

==========
Sample ResourceManager:

public final class ResourceManager {
private static ResourceManager inst;
private static Logger logger = Logger.getLogger(ResourceManager.class);

private ResourceManager(){

}

public static synchronized ResourceManager getInstance(){
if (inst==null)
inst= new ResourceManager();
return inst;
}
public Object clone() throws CloneNotSupportedException
{
throw new CloneNotSupportedException();
}

public Properties getResource(String name){
Properties r = new Properties();
try{
name=name.replace('.', '/');
r.load( ClassLoader.getSystemResourceAsStream(name+".properties") );
}catch(IOException e){
logger.error(e);
}
return r;
}
public Properties getResource(Class name){
return getResource(name.getName());
}
}



=========
The ResourceManager class does not have to be a singleton, but it gives the added bonus of being memory efficient because creating multiple instances of it is no longer necessary; it having only one usable method. It can also be modified so that file access is threaded, preventing any slowdown on particularly large files. But thats for another trick.