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













2018-08-15

Stuck for 2.5 hrs...


codecommit
git

facing unable to push
keep commit everything
then pull
and face conflict
fix 1 by 1
then add fixed files into index, then commit and push again.



spring 注解 @ResponseBody 返回JSON 能不能设置他不返回为 null 的值


Searched by:
@responsebody without null value
https://www.google.com.sg/search?q=%40responsebody+without+null+value&oq=%40responsebody+without+null+value&aqs=chrome..69i64.7166j0j1&sourceid=chrome&ie=UTF-8


Reference URL:
https://segmentfault.com/q/1010000002522525


设置jackson忽略null

<mvc:annotation-driven>
    <mvc:message-converters register-defaults="true">
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper">
                <bean class="com.fasterxml.jackson.databind.ObjectMapper">
                    <property name="serializationInclusion">
                        <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
                    </property>
                </bean>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>




2018-08-07

spring form checkbox auto add hidden input css not working










https://stackoverflow.com/questions/43749850/how-to-place-a-tag-element-between-the-input-tag-and-the-hidden-field


https://jsfiddle.net/DiogoBernardelli/rLutkcx0/

.switch input[type="checkbox"]:checked + input[type="hidden"] + label:after{
    left: 23px;
}
.switch input[type="checkbox"]:checked + input[type="hidden"] + label{
    background-color: #fff;
    color: #f00;
}


2018-08-04

log4j2 json jsn test maven pom






using json jsn for log4j2 configuration must add jackson-databind in maven pom.xml

log4j2 slf4j maven





See this?
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.





Add this

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.1</version>
</dependency>


If not found, then add repo

<repositories>
  <repository>
    <id>apache.snapshots</id>
    <name>Apache Snapshot Repository</name>
    <url>https://repository.apache.org/snapshots</url>
    <releases>
      <enabled>false</enabled>
    </releases>
  </repository>
</repositories>

2018-08-01

java.lang.IllegalArgumentException: Attribute 'value' is required when binding to non-boolean values





java.lang.IllegalArgumentException: Attribute 'value' is required when binding to non-boolean values







Resource URL:

https://blog.csdn.net/goldenfish1919/article/details/7039104



Google Referrals