2018-11-05

org.apache.maven.plugin.war.WarMojo cannot compile





hint source URL: https://issues.apache.org/jira/browse/MWAR-279


sample solution:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<url>http://maven.apache.org</url>

<properties>
<jdk.version>1.7</jdk.version>
<context.path>wilasBase2</context.path>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>

</dependencies>
<build>
<finalName>x</finalName>
<plugins>
<!-- Maven compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>

</plugins>
</build>
</project>

2018-10-18

java regex between multiple lines



Searched by: java regex between multiple lines

Source URL:
https://stackoverflow.com/questions/3651725/match-multiline-text-using-regular-expression



First, you're using the modifiers under an incorrect assumption.
Pattern.MULTILINE or (?m) tells Java to accept the anchors ^ and $ to match at the start and end of each line (otherwise they only match at the start/end of the entire string).
Pattern.DOTALL or (?s) tells Java to allow the dot to match newline characters, too.
Second, in your case, the regex fails because you're using the matches() method which expects the regex to match the entire string - which of course doesn't work since there are some characters left after (\\W)*(\\S)* have matched.
So if you're simply looking for a string that starts with User Comments:, use the regex
^\s*User Comments:\s*(.*)
with the Pattern.DOTALL option:
Pattern regex = Pattern.compile("^\\s*User Comments:\\s+(.*)", Pattern.DOTALL);
Matcher regexMatcher = regex.matcher(subjectString);
if (regexMatcher.find()) {
    ResultString = regexMatcher.group(1);
} 
ResultString will then contain the text after User Comments:
















2018-10-11

Project Facets doesn't have 1.8 as option for java.


Java compiler level does not match the version of the installed Java project facet. PROJECT_ABC123 Unknown Faceted Project Problem (Java Version Mismatch)





source URL: https://stackoverflow.com/questions/28995358/getting-project-facet-java-version-1-8-is-not-supported-in-eclipse-luna

I solved the problem. Go to Project Properties -> Project Facets -> Runtime -> New -> Add a tomcat server and in JRE select JRE1.8.0_XX.




2018-09-18

Why most posts telling slf4j is better than apache commons log to work with log4j.


Edited: 2019-Aug-08_pm063733

Recently due to some event, lead me to double check again about:


  1. slf4j
  2. log4j
  3. apache commons logging


Which facts so far I found were showing different story...






https://commons.apache.org/proper/commons-logging/

1.0.4 Release - 16 Jun 2004

The 1.0.4 release of commons-logging is a service release containing support for both the 1.2.x and 1.3.x series of Log4J releases.






https://www.slf4j.org/news.html

13 April 2005 - start of work on SLF4J project

Launch of the SLF4J project. Work has begun on the web-site, svn repositories as well as the source code.






https://www.quora.com/What-is-the-best-logging-framework-for-Java-for-new-projects

https://stackoverflow.com/questions/41633278/can-we-use-all-features-of-log4j2-if-we-use-it-along-with-slf4j-api/41635246#41635246

https://www.google.com/search?q=apache+common+logging+vs+slf4j&oq=apache+common+logging+vs+slf4j&aqs=chrome..69i57j0l2.1034j0j7&sourceid=chrome&es_sm=93&ie=UTF-8




java best logging framework

https://stackoverflow.com/questions/41498021/is-it-worth-to-use-slf4j-with-log4j2

https://www.loggly.com/blog/benchmarking-java-logging-frameworks/

https://stackify.com/compare-java-logging-frameworks/

http://www.java-logging.com/comparison/

https://www.baeldung.com/java-logging-intro




















2018-08-20

Spring JpaRepository Hibernate Jackson Junit Test, Controller.








Error:

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: xx.xx.xx.db.xx.xx.xx.xx, could not initialize proxy - no Session at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:588) [hibernate-core-5.3.3.Final.jar:5.3.3.Final] at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:207) [hibernate-core-5.3.3.Final.jar:5.3.3.Final] at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:151) [hibernate-core-5.3.3.Final.jar:5.3.3.Final] at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:261) [hibernate-core-5.3.3.Final.jar:5.3.3.Final] at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:97) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3893) [jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3207) [jackson-databind-2.9.5.jar:2.9.5]



Config to clear error:


Reference URL:
https://coderleaf.wordpress.com/2016/11/07/jackson-serialization-and-hibernate-lazy-loading/

@Configurationpublic class WebMvcConfig extends WebMvcConfigurationSupport{     @Override    protected void extendMessageConverters( List<HttpMessageConverter<?>> converters ) {        for ( HttpMessageConverter<?> converter : converters ) {            if ( converter instanceof MappingJackson2HttpMessageConverter ) {                MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;                                ObjectMapper objectMapper = jacksonConverter.getObjectMapper();                                 //--- register hibernateModule in MappingJackson2HttpMessageConverter.objectMapper                objectMapper.registerModule(new Hibernate4Module());                 //--- other configurations                jacksonConverter.setPrettyPrint( true );                objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);                                objectMapper.enable(SerializationFeature.INDENT_OUTPUT);            }        }                 super.configureMessageConverters(converters);    } }






xml config to clear error

Reference URL:
https://stackoverflow.com/questions/43946323/spring-and-mappingjackson2httpmessageconverter-and-registermodule




<mvc:annotation-driven>
    <mvc:message-converters register-defaults="true">
        <bean
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="objectMapper" />
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

<bean id="objectMapper"
    class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">

    <property name="featuresToDisable">
        <array>
            <util:constant
                static-field="com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS" />
        </array>
    </property>

    <property name="dateFormat">
        <bean class="java.text.SimpleDateFormat">
            <constructor-arg type="java.lang.String" value="yyyy-MM-dd"></constructor-arg>
        </bean>
    </property>

    <property name="modulesToInstall"
        value="
        com.fasterxml.jackson.datatype.jdk8.Jdk8Module,
    com.fasterxml.jackson.datatype.jsr310.JavaTimeModule,
    com.fasterxml.jackson.module.paramnames.ParameterNamesModule" />
</bean>













2018-08-17

java tomcat session path



Case deploy to tomcat/webapps/projectA

but access to page by projectA.domain.com/

mean i have tomcat/webapps/projectA/gg.jsp

then deploy to server access by projectA.domain.com/gg.jsp

and facing session path issue.


Solutions refer to:
https://stackoverflow.com/questions/12755499/how-to-change-jsessionid-cookie-path-to-server-root-in-spring-app-on-jetty

<session-config>
    <session-timeout>15</session-timeout>
    <cookie-config>
        <name>JSESSIONID</name>
        <path>/</path>
        <http-only>false</http-only>
        <secure>false</secure>
    </cookie-config>
</session-config>








Reference URL:
https://www.mkyong.com/servlet/how-to-configure-the-session-timeout-in-servlet/

1) Timeout in the deployment descriptor (web.xml)
– Specified the timeout value in “minute” , enclose with “session-config” element.
<web-app ...> <session-config> <session-timeout>20</session-timeout> </session-config></web-app>CopyThe above setting is apply for the entire web application, and session will be kill by container if client doesn’t make any request after 20 minutes.




Reference URL:
https://stackoverflow.com/questions/40753753/cookies-with-path-path-and-jsessionid













Google Referrals