Pages

Friday, May 19, 2017

Cannot nest 'projectname/src/main/java' inside 'projectname/src'. To enable the nesting exclude 'main/' from 'projectname/src' in eclipse maven project

I noticed following error in my project in eclipse.
       
Cannot nest 'projectname/src/main/java' inside 'projectname/src'. To enable the nesting exclude 'main/' from 'projectname/src'

due to this error also my test of junit was not working. and problem was due to reason that i changed eclipse java project into maven project and in the pom file eclipse added
 <sourceDirectory>src</sourceDirectory>
 and due to this maven plugin was giving error after removing this line plugin error gone and also junit test were fine.


Wednesday, May 17, 2017

junit unable to find junit test annotation class gives compilation error

In Eclipse I noticed sometimes for maven projects  (mostly i assume if eclipse project converted in maven project nature)  if you notice compilation error "package org.junit does not exist" that means he is unable to find annotation class while doing compilation.
following could be the probable errors.

1. in your pom file you did not add the dependency of junit  add it as
       

             <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.8.1</version>
                    <scope>test</scope>
             </dependency>

 

2. although above dependency is there it works fine if you remove scope which is not the right solution as your test class then gets added to your final jar or war package.




sol1: one solution that i found,  probably it could be issue with eclipse. that in such a case I make sure that maven dependency is shown in the package explorer of eclipse. for this  I do following
on project from project explorer right click select menu "Add Libraries..." there you select "Maven managed Dependencies" click ok and you will see dependencies are added properly by eclipse and in dependencies you see junit library is refereed

now it will compile and run your test.

sol2: another solution i noticed that when eclipse java project converted in to maven project specially if you assume everything right still it gives error even after trying sol1 above, then please look into pom file and from your build remove "<sourceDirectory>src</sourceDirectory>" this as it causes problem to maven plugin to read test folder properly, after removed it worked properly

I also notice my bad but sometimes we forget that junit needs class name also should have Test key word prefix or post-fix otherwise it gives error test run 0

hope this helps someone.!!

Wednesday, June 15, 2016

support for special charecter while compile in eclipse unmappable character for encoding UTF-8

I faced problem while compiling xsd to java using apache xmlbeans maven plugin that
generated code was not matched same as in xsd, given xsd file has special German character in element as


 <xs:enumeration value="in Ablöse"/> 
and when it gets converted to java expected as

static final Enum IN_ABLÖSE = Enum.forString("inAblöse");



my maven plugin was failed to write proper special character in generated java code. though in eclipse editor

i able to see proper character for xsd file but generated java was not. After research i found that its affected by eclipse IDE and the maven pom file that you specify, I tried to google and found that you can provide encoding type to maven pom as below


       

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <UTF-8</encoding>
    </configuration>
</plugin>
 
 


I also noticed that this is not sufficient many maven plugins will by default use the "project.build.sourceEncoding" property and this applies to all plugin mentioned to your pom file.

I did following

1 First i opened xsd files in textpad and changed the file format to 'PC' and encoding to 'UTF-8'.

2 Next in my eclipse preferences kept xsd file encoding type as UTF-8 this can be done as  windows>preferences>General>Content Types>Text>xml>xsd check down default encoding to UTF-8.

3 Right click project>properties>Resources>Text file encoding>set to inherited from container (Cp1252).

4 In pom file remove "project.build.sourceEncoding" property so that compile will take default of container/eclipse editor properties


and this worked.

Friday, November 6, 2015

jdbc connection from java callout in osb without provider url

Recently  I was developing a javacallout from osb where i was needed to call a jdbc that is configured on weblogic of osb. and did not want to configure provider url for creating database connection lookup  that goes as follows.

Properties p=new Properties() p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");  p.put(Context.PROVIDER_URL,"t3://hostname:port");

problem here was that for javacallout if to be put in jar provider url cannot be hardcoded neither good way to pass as parameter in method call or putting in properties file is also not possible as osb do not allow uploading as resources (though may be possible to put in jar but that too i did not want)

So after carefully reading oracle document i found that if you are creating server side objects / application that run in the same jvm of the weblogic server, as in my case javacallout in osb, you do not need to specify the Context.PROVIDER_URL property. Usernames and passwords are required only if you want to sign in as a specific User.
To create a Context from within a server-side object, you first must create a new InitialContext, as follows:

  Context ctx = new InitialContext();

You do not need to specify a factory or a provider URL. By default, the context is created as a Context and is connected to the local naming service.

and this solved my problem !



Tuesday, September 30, 2014

Problems using JAX-WS 2.1 and JAXB 2.1 with JDK1.6 ?

Recently while working on web services I faced following problem where I was bound to use jdk1.6 to create web service because current version of weblogic11g and 12c works on jdk1.6.

       [ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Data/work/OSB/OSB_Workspace/SOASampleWS_HV3/src/generated/jaxws/at/spardat/soa/osb/soap/osbsoapexample/v1/OsbSoapExample.java:[46,9] C:\Data\work\OSB\OSB_Workspace\SOASampleWS_HV3\src\generated\jaxws\at\spardat\soa\osb\soap\osbsoapexample\v1\OsbSoapExample.java:46: cannot find symbol
symbol  : constructor Service(java.net.URL,javax.xml.namespace.QName,javax.xml.ws.WebServiceFeature[])
location: class javax.xml.ws.Service


I am using Maven and problem that I found that with wsimport code gets generated properly but while compiling generated code I get error as shown above. after investigation I found that code gets generated with JAV-WS2.1 as required but while compiling code with JDK1.6 java uses its own JAX-WS library provided in jdk which is older version and do not have this constructor defined in it. to overcome on this issue following is the way.

1. most simple approach is to copy jaxb-api.jar, jaxws-api.jar in your installed JDK1.6 /lib/endorsed directory.

2. if you do not want to do this and using wsimport/wsgen of JAX-WS2.1 then you can use endorse feature as WSIMPORT_OPTS=-Djava.endorsed.dirs=%JAXWS_HOME%/lib or WSGEN_OPTS=-Djava.endorsed.dirs=%JAXWS_HOME%/lib, option while calling your script, note that JAXWS_HOME points to your JAX-WS2.1 installation directory

3. if you are using maven to do the build of project then set following elements endoresedirs to your maven-compiler-plugin.

&ltplugin&gt
    &ltgroupId&gtorg.apache.maven.plugins&lt/groupId&gt
    &ltartifactId&gtmaven-compiler-plugin&lt/artifactId&gt
    &ltversion&gt3.1&lt/version&gt
        &ltconfiguration&gt
            &ltsource&gt1.6&lt/source&gt
            &lttarget&gt1.6&lt/target&gt
            &ltcompilerArguments&gt
             &ltendorseddirs&gt${project.build.directory}/endorsed&lt/endorseddirs&gt
           &lt/compilerArguments&gt
        &lt/configuration&gt
&lt/plugin&gt