How can I suppress specific Checkstyle rules in Eclipse? - checkstyle

I'm trying to use suppression filter but an unexpected error occurs.
Following is an error message.
"cannot initialize module
SuppressionFilter - Cannot set property 'file' in module SuppressionFilter to
'checkstyle-suppressions.xml': unable to find checkstyle-suppressions.xml - Document root element "suppressions", must match DOCTYPE root "module"."
Could you let me know how can I resolve this error?
Followings are a configuration file and a suppression file contents which I used.
I configured the suppression filter through eclipse menu(windows > preferences > checkstyle > configure > known modules Filter > Suppression Filter > add)
======================================
configuration file is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="TreeWalker">
<module name="MagicNumber">
<property name="ignoreNumbers" value="-1, 0, 1"/>
</module>
</module>
</module>
===================================
suppression filter file is ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<suppressions>
<suppress checks="MagicNumberCheck"
files="Home.java"
lines="350-370"/>
</suppressions>

Your suppression filter file uses the 1.1 syntax, but claims to be using the newer 1.3 syntax. Exchange the header like so:
<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
Also, your configuration file must reference the suppression filter. Add a module definition like this (add it before the last closing </module> tag, not under Treewalker):
<module name="SuppressionFilter">
<property name="file" value="${workspace_loc}/MyProject/suppressions.xml"/>
</module>
Using the ${workspace_loc} variable makes sure that this works even when you copy or rename the workspace.

Related

WildFly 10 NoDefClassFound com/fasterxml/jackson/jaxrs/cfg/ObjectWriterModifier

To ease developing my endpoints returning JSON, I want to enable prettyprinting.
The solution I'm tyring to implement is adding a filter that injects an ObjectWriterModifier enabling the default pretty printer, if the query string is ?pretty=1.
Deployment fails as it cannot find the class com/fasterxml/jackson/jaxrs/cfg/ObjectWriterModifier
which is contained in jackson-jaxrs-base-2.7.4.jar under modules/system/layer/base/com/fasterxml/jackson/core/jaxrs/jackson-jaxrs-json-provider of my WildFly 10 installation.
In my build.gradle I do specify the dependicy as provided:
dependencies {
providedCompile 'javax:javaee-api:7.0'
providedCompile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
providedCompile 'com.fasterxml.jackson.core:jackson-annotations:2.7.4'
providedCompile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.7.4'
}
Here is module.xml for jackson-jaxrs-json-provider
<module xmlns="urn:jboss:module:1.3" name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider">
<resources>
<resource-root path="jackson-jaxrs-json-provider-2.7.4.jar"/>
<resource-root path="jackson-jaxrs-base-2.7.4.jar"/>
<resource-root path="jackson-module-jaxb-annotations-2.7.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.ws.rs.api"/>
<module name="javax.xml.bind.api"/>
<module name="com.fasterxml.jackson.core.jackson-annotations"/>
<module name="com.fasterxml.jackson.core.jackson-core"/>
<module name="com.fasterxml.jackson.core.jackson-databind"/>
</dependencies>
</module>
I don't see how WildFly can't find a class that's inside one of the jars it provides
Have a look at the class loading documentation. You may need to add a module dependency as all modules aren't just automatically added as a dependency to deployments.

Connecting database with hibernate

I know thats a known problem and i made my research but still couldnt find a proper answer and what to do, so my last hope is here. The problem is, when i use phpAdmin i can connect and create my tables in m database. But when i run hibernates connection wizard, after entering the connection properties, if i press the test connection it gives me this error :
"Timeout expired. IDE unable to establish connection. Check your proxy settings or try again later. The server may be unavailable at the moment.   You may also want to make sure that your firewall is not blocking network traffic."
My hibernate.cfg.xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.11.83.2:3306</property>
<property name="hibernate.connection.username">admin1s6nbcM</property>
<property name="hibernate.connection.password">*******</property>
</session-factory>
</hibernate-configuration>
I m suspecting that there is something wrong with MySQL Java Connector library ;
dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
because i get this warning when i build my application:
Some problems were encountered while building the effective model for cardsystelefonbuch:cardsystelefonbuch:war:1.0
'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: mysql:mysql-connector-java:jar -> version 5.1.25 vs 5.1.30 # line 83, column 13
It is highly recommended to fix these problems because they threaten the stability of your build.
For this reason, future Maven versions might no longer support building such malformed projects.
Any ideas would be greatly appreciated !

Could not load AnnotationConfiguration hibernate ,when internet is not connected

i am using hibernate 4.0 and mysql 5.6 with eclipse luna(v4.4.1),
i am using hibernate annotations in my project.
When i make changes to any table of DB, I always generate hibernate annotations automatically via eclipse hibernate configurations.
my question is that:
when i do not connect internet and want to generate hibernate annotations i get this ERROR : [Classpath]: Could not load AnnotationConfiguration (screen shot also attached) and when i connect to internet i do not face this error.
is this bug or feature ?? if this is feature then how can i generate hibernate annotations offline?
thanks!
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">myroot</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.72.128:3306/hesco</property>
<property name="hibernate.connection.username">myroot</property>
</session-factory>
</hibernate-configuration>
You could try putting all the dtds needed in local.
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd
In fact your url in the hibernate confil file should be the cause :
192.168.72.128
Try localhost if it's your ip adress.
thanks to Xavier Bouclet who guide me about dtd problem, I did google it and find my solution from this link
i put below DOCTYPE to my hibernate.cfg.xml file and now i can work offline
<!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">myroot</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.72.128:3306/hesco</property>
<property name="hibernate.connection.username">myroot</property>
</session-factory>
</hibernate-configuration>

Hibernate not working Intellij driver not found

I have a web application and I´m trying to get Hibernate working.
As soon as I call my webservice, which uses Hibernate, I´m getting the error
org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver could not be loaded
I´ve read some posts on SO, where the solution was to add the driver to the classpath.
What I first did is, I´ve added the dependency to my pom.xml, but afterwards it did not download any libs, so I downloaded it manually with maven.
Now I´ve "mysql-connector-java-5.1.31.jar" in my libs and added the stuff to my project.
But it had no effect.
Afterwards I´ve copied the lib to my TOMCAT/libs folder which also had no effect.
Why can´t the driver be loaded and how can I fix it?
My hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/myproject</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">hibernate</property>
<property name="connection.password">hibernate</property>
<mapping class="database.DevicetableEntity"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>

OpenJPA + MySQL issue

I have been using OpenJPA with MySQL. Here is my persistence.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!--
For DB connectivity
-->
<persistence version="1.0">
<persistence-unit name="jpa">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.Login</class>
</persistence-unit>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/jpa"/>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value="root"/>
<property name="openjpa.jdbc.DBDictionary" value="mysql(SimulateLocking=true)"/>
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
</properties>
</persistence>
When I am executing my Java class, I am getting an exception which is given below. The same code is working fine if I use hibernate and change configuration in persistence.xml, But it is not working in OpenJPA. Can anyone help to solve this?
Exception in thread "main" javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "jpa" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl from provider: org.apache.openjpa.persistence.PersistenceProviderImpl
at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
at com.JPALogin.main(JPALogin.java:26)
Caused by: <openjpa-2.2.0-r422266:1244990 nonfatal general error> org.apache.openjpa.util.GeneralException: org.xml.sax.SAXException: file:/E:/work/JPAPlain/build/classes/META-INF/persistence.xml [Location: Line: 5, C: 28]: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'persistence'.
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource(XMLMetaDataParser.java:427)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:347)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:324)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:297)
at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationParser.parse(PersistenceProductDerivation.java:772)
at org.apache.openjpa.persistence.PersistenceProductDerivation.parseResources(PersistenceProductDerivation.java:556)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:522)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:336)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:86)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:153)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:62)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
... 2 more
How about you try something like this?
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<!-- For DB connectivity -->
<persistence-unit name="jpa">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.Login</class>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/jpa" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionUserName" value="root" />
<property name="openjpa.ConnectionPassword" value="root" />
<property name="openjpa.jdbc.DBDictionary" value="mysql(SimulateLocking=true)" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
</properties>
</persistence-unit>
</persistence>
SAXParseException: cvc-elt.1: Cannot find the declaration of element 'persistence'. at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource
I can't be sure, but it looks like the XML parser of your persistence.xml file is trying to validate the XML against a DTD, and it is complaining because it can't get a (useful) DTD. You might want to change the first line of your XML file to the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
I would not expect an invalid XML file or missing DTD to cause the parser to crash with a mysterious exception. So if that is the cause of the problem, I'd say the persistence provider code had a bug in it. I'd expect a more useful exception, with a message saying "invalid XML", or some such.