Generating Checkstyle Reports (with extended checks) - java

I have some own extended checks. I have exported them as plug-in and in Eclipse, they are showing warning/error. So the extended checks are working fine.
Now I want to generate a report of the violations in HTML format.
I have checked this, and this works fine if no extended checks are included in rule.xml file. But in case of extended checks, the ant build is giving the error.
The error is:
BUILD FAILED
D:\Java_Work\JUnit_CheckStyle\buildCheckStyle.xml:12: Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate InterfaceModifier
InterfaceModifier is my extended check, and it works fine in eclipse.
In build.xml, where to provide the extendedCheck.jar so that I get the required result?

I have found out the following solution, which is working fine.
extract checkstyle-x.x-all.jar
copy the extended classes in the extracted directory
copy the metadata,message and properties file of extended check in the same directory.
if any of the file is alreasy present, then edit the file and add the content from extended checks.
create a new .jar file including all these.
in ant build.xml <taskdef>, set this .jar as classpath
Like, after done till 2nd step, I found checkstyle_packages.xml is already present, so I edit it and added the content from extended one in proper position.
Previous Version:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-packages PUBLIC
"-//Puppy Crawl//DTD Package Names 1.0//EN"
"http://www.puppycrawl.com/dtds/packages_1_0.dtd">
<checkstyle-packages>
<package name="com.puppycrawl.tools.checkstyle">
<package name="checks">
<package name="annotation"/>
<package name="blocks"/>
<package name="coding"/>
<package name="design"/>
<package name="duplicates"/>
<package name="header"/>
<package name="imports"/>
<package name="indentation"/>
<package name="javadoc"/>
<package name="metrics"/>
<package name="modifier"/>
<package name="naming"/>
<package name="regexp"/>
<package name="sizes"/>
<package name="whitespace"/>
</package>
<package name="filters"/>
</package>
</checkstyle-packages>
Changed Version:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-packages PUBLIC
"-//Puppy Crawl//DTD Package Names 1.0//EN"
"http://www.puppycrawl.com/dtds/packages_1_0.dtd">
<checkstyle-packages>
<package name="com.puppycrawl.tools.checkstyle">
<package name="checks">
<package name="annotation"/>
<package name="blocks"/>
<package name="coding"/>
<package name="design"/>
<package name="duplicates"/>
<package name="header"/>
<package name="imports"/>
<package name="indentation"/>
<package name="javadoc"/>
<package name="metrics"/>
<package name="modifier"/>
<package name="naming"/>
<package name="regexp"/>
<package name="sizes"/>
<package name="whitespace"/>
</package>
<package name="filters"/>
</package>
<!-- Added this lines -->
<package name="myCheck">
<package name="checks"/>
</package>
<!-- -->
</checkstyle-packages>
now the build file is running successfully and in the report I'm getting violation of extended checks too.

Related

struts.convention.result.path is not working in Struts2

My current project structure is as follows
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
My assignment is to put all JSP pages inside folder WEB-INF and do all relative changes in the project.
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
So I have to update all result tag in struts.xml
<result name="success">/View/TestPage.jsp</result>
to
<result name="success">/WEB_INF/View/TestPage.jsp</result>
After search on web I found a plugin - struts convention plugin to achieve this, But it follows its Naming convention.
Can I override Struts convention plugin configuration (that will not follow its naming convention)?I have tried too, but it is not reflecting. My struts.xml is
<struts>
<constant name="struts.devMoade" value="true" />
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
<package name="test" extends="struts-default" namespace="/">
<action name="hello1" class="testAction.Hello1Action">
<result name="success">/TestPage.jsp</result>
</action>
</package>
</struts>
When I run
localhost:8080/project-name/hello1
It displays error 404.But if I change result in struts.xml as
<result name="success">/WEB-INF/View/TestPage.jsp</result>
It works fine.
I don't wanna do changes in all result tags.How can I achieve this by doing changes at one place?
The convention plugin uses a different configuration provider and this constant only works with configuration created by convention.
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
If you want to override the convention configuration you should use annotations.
package testAction;
#ParentPackage("json-default")
#Namespace("/")
#Action(value="hello1", results=#Result(name = "success", location="TestPage.jsp"))
public class Hello1Action extends ActionSupport {
}

Struts2: Setting constant struts.action.extension to "," not working

I am working on struts2-archetype-starter. Got a demo struts 2 project by executing:
mvn archetype:generate -B -DgroupId=demoStrutsStarter -DartifactId=DemoStrutsStarter -DarchetypeGroupId=org.apache.struts -DarchetypeArtifactId=struts2-archetype-starter
I modified my struts.xml and added a struts.action.extension constant declaration. Now it looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.action.extension" value=","/>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<package name="myPackage" extends="struts-default">
<default-action-ref name="index" />
<action name="index" class="demoStrutsStarter.IndexAction">
<result>/jsp/index.jsp</result>
</action>
<action name="helloWorld" class="demoStrutsStarter.HelloWorldAction">
<result name="input">/jsp/index.jsp</result>
<result>/jsp/helloWorld.jsp</result>
</action>
</package>
</struts>
But, I am getting a 404 error when I type:
http://localhost:8080/DemoStrutsStarter/index
I am not sure where I am wrong. Can anybody please help me find out why I am unable to call actions without .action extension?
Try adding a namespace to your package:
<package name="myPackage" namespace="/" extends="struts-default" >
Try this out in both results
result 1
<result>/WEB-INF/jsp/index.jsp</result>
result 2
<result>/WEB-INF/jsp/helloWorld.jsp</result>
else check your package name is correct or not.
by default, it's name default
try this links. it may help
1.stack overflow link 1
2.link 2 mkyong
3.stack overflow link 3

Struts unable to find action class

Been banging my head for quiet sometime now as I don't seem to understand why struts is unable to find my action class.
This is my struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="getTutorial" class="org.mypackage.actions.TutotrialAction" method="execute">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>
</struts>
This is my project structure
And finally this is the error that I see
Clearly the action seem to be present, not sure why it is unable to find it. Another eye ball would be appreciated!
Small typo:
<action name="getTutorial" class="org.mypackage.actions.TutotrialAction" method="execute">
^
should be
<action name="getTutorial" class="org.mypackage.actions.TutorialAction" method="execute">

How to remove the extensions from url

I have designed an application using struts2, and need to remove the extensions for example
www.myweb.com/register.action
How to remove the .action so when I click on register it call www.myweb.com/register without action extension?
I use the following
Register
I've found the answer. I should change the struts configuration as following:
<struts>
<constant name="struts.action.extension" value=""/>
<package name="default" extends="struts-default">
<action name="register">
<result type="tiles">register</result>
</action>
</package>
</struts>

Resource ... is not available

If i try to use this action (test2) it always returns "The requested resource (/WebApplication4/newFolder/test2.jsp) is not available."
Running tomcat6 and netbeans 6.7.1
config.xml (it is included in struts.xml):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="mypackage" namespace="/" extends="struts-default">
<action name="test2">
<result>/newFolder/test2.jsp</result>
</action>
</package>
</struts>
alt text http://img2.pict.com/87/b7/dc/1676731/0/clipboard4.jpg
but if i change result value from "/newFolder/test2.jsp" to "test.jsp" - everything works.
Solved, needed:
<result>/WEB-INF/newFolder/test2.jsp</result>

Categories

Resources