JaxB #XmlRootElement result in "Cannot resolve xml element declaration" - eclipse

I was using JAXB as DTO to set a stable interface between Server and Clients. Anyways this doesn't matter. What matters is I created a set of classes that result in the following compile error.
Cannot resolve XML element declaration with namespace 'namespace' and
name 'name' in this context
Eclipse underlined "name" inside quotes as an error. This class is manually created instead of xjc generated.
#XmlRootElement(name="name", namespace="namespace")
#XmlType(name="")
public class UserDTO {
private UserType userType;
#XmlElement
public UserType getDTO(){
return userType;
}
public void setDTO(UserType userType){
this.userType=userType;
}
}
where UserType is a xjc generated class
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "userType", propOrder = {
"userId",
"userName"
})
public class UserType {getter;setter}
So basically UserDTO is just a wrapper that wraps up sub jaxb types.
I'm not sure if it was platform dependent (which it shouldn't be), anyways, just to mention that this code worked perfectly on Netbeans, but when it come to Eclipse, the error prevented the compilation.
The Environment running the project was:
1. MacOsX Lion
2. JDK: 1.6.0_37
3. Eclipse Version: Juno with Package 1
4. JAXB Platform: Generic JAXB 2.1
Please anyone can share some idea?
ps: I added the JDK info and Libraries setting as Manuel suggested.

I faced this issue, you have more than one schema, at least two, both of them don't have namespace, just assign namespace to one of them.

Related

How to configure Auto-Value with Eclipse and Gradle?

I want to use Google’s Auto-Value in a Gradle java-library project in Eclipse.
My class:
#AutoValue
public abstract class Pairing implements Comparable<Pairing> {
static Pairing create(final Participant white, final Participant black) {
return new AutoValue_Participant(white, black);
}
private final transient Participant white;
private final transient Participant black;
}
https://github.com/google/auto/blob/master/value/userguide/index.md says: To use Auto-Value in Gradle, simply use:
dependencies {
// Use 'api' rather than 'compile' for Android or java-library projects.
compile "com.google.auto.value:auto-value-annotations:1.6.2"
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
}
I did this, and it didn’t work:
> Task :compileJava FAILED
D:\QNo_Dokumente\Java\workspace\SwissCoffee\src\main\java\de\qno\swisscoffee\Pairing.java:20: error: cannot find symbol
return new AutoValue_Participant(white, black);
^
symbol: class AutoValue_Participant
location: class Pairing
D:\QNo_Dokumente\Java\workspace\SwissCoffee\build\classes\java\main\de\qno\swisscoffee\AutoValue_Pairing.java:11: error: constructor Pairing in class Pairing cannot be applied to given types;
Then i googled and found a Gradle APT plugin that should solve all problems. But the documentation of the plugin says: it is unnecessary for Gradle >= 4.6, and since i’m using gradle 5.4, i should be fine without that plugin.
How get i Auto-Value integrated?
Ok, you should never code after midnight. And you should solve problems by discarding any code written after midnight.
The source code simply was wrong. Private fields instead of abstract methods, false name of the autoValue autogenerated class.
Sorry for inconvenience. No further reply necessary. All docs found with google are valid.

Eclipse custom #NonNull annotation ignored

I would like to use the "null analysis" feature of Eclipse but I would rather use the javax.annotation.Nonnull annotation than the org.eclipse.jdt.annotation.NonNull annotation. I can't seem to get Eclipse to recognize any custom annotations I configure.
I'm using Eclipse Luna 4.4.2.
I created a new test project that contains only the following class:
package org.example;
import javax.annotation.Nonnull;
public class OmgNulls {
public static void main(String[] args) {
#Nonnull String test = null;
System.out.println(test);
}
}
My compiler settings are configured to use the javax annotations:
My project's includes the checker-1.8.10 JAR to provide the annotations.
With these settings, Eclipse reports 0 errors.
If I check "Use default annotations for null specifications" and change my test class to use Eclipse's annotation, I get:
Anyone know what I'm doing wrong or is this an Eclipse bug maybe?
I've also tried the jsr305 JAR from google instead of checker in case that was an issue but that didn't help.

WELD-001408 Unsatisfied dependencies for type [DataSource] with qualifiers

I have the following that is causing the subjected error message in APP-A
#Inject #CtcDB
private DataSource ds;
I'm using an identical pattern with APP-B which does not complain of this error.
When I hover over ds in Eclipse while holding down the ctrl key, I get the following context menu for APP-B
Open #Inject Bean Resource.ds
Open Declaration
Open Declared Type
but in the APP-A with the dependency error I only get
Open Declaration
Open Declared Type
// The Resources class is basically the same b/n both apps except the qualifier is #CommitmentDB for APP-B
public class Resources {
#Produces
#Resource(mappedName="java:jboss/datasources/myjndids")
#CtcDB
private DataSource ds;
// And my annotation
#Qualifier
#Retention(RUNTIME)
#Target({ METHOD, FIELD, PARAMETER, TYPE })
public #interface CtcDB{
}
I know CDI is active (I have a beans.xml in WEB-INF) because I have a POM dependency which contains some injectable beans. When hovering with the ctr key for those injections I get the expected context menu (in both apps)
OK I figured it out myself. In the Resources class I had the wrong import for DataSource
import javax.activation.DataSource; \\instead of
import javax.sql.DataSource;
I must have clicked on the wrong Eclipse Quickfix and imported the wrong package.

Remote EJB Client Eclipse

I've been trying for some time to learn Java EE but I could never run an EJB example. Oracle's guide uses netbeans but I must learn how to do it in Eclipse. Neither did books did any help or youtube videos.
I can run servlets, jsp, jsf without problems but I always had problems with EJBs. What am I missing?
The problem is configuration within Eclipse I think.
My Project Structure in Eclipse is the following:
The code of HelloWorld.java file:
package helloworld.ejb;
import javax.ejb.Remote;
#Remote
public interface HelloWorld {
public String outputHelloWorld();
}
Code of the HelloWorldBean.java file
package helloworld.ejb;
import javax.ejb.Stateless;
#Stateless
public class HelloWorldBean implements HelloWorld {
public String outputHelloWorld() {
return "Hello World!";
}
}
Code of the HelloWorldClient.java
package helloworldprojectclient;
import javax.ejb.EJB;
import helloworld.ejb.HelloWorld;
public class HelloWorldClient {
#EJB
private static HelloWorld helloWorld;
public static void main (String[] args) {
System.out.println(helloWorld.outputHelloWorld());
}
}
I am using Glassfish 4.0 as a server. The HelloWorldProject is an "EJB Project" while "helloworldprojectclient" is a regular Java Project and i've added javaee.jar (from the glassfish directory) to the buildpath.
When I try to run the HelloWorldClient.java I get the following exception:
Exception in thread "main" java.lang.NullPointerException
at helloworldprojectclient.HelloWorldClient.main(HelloWorldClient.java:10)
which is the following line: System.out.println(helloWorld.outputHelloWorld());
What is the problem? I mention i'm a total beginner at EJBs. Thank you!
Just in case you are still intrested in this:
The first version doesn´t work because you are trying to inject an ejb reference in a class that is not managed by a Container. When you execute the main method, the #EJB annotation is ignored, thus 'HelloWorld' class member is never initialized.
In order to execute this code without modification, you need execute the class in a Application Client Container that will inject the ejb reference.
Your second version runs because instead of to delegate to Container, you are getting the ejb reference through the JNDI service. This is the suggested way when Container injection is no available.
I've managed to make it work. I don't know if this is the correct way but in the "helloworldprojectclient" if you set the buildpath's Project tab and add HelloWorldProject then on the Libraries tab add appserv-rt.jar and javaee.jar (both from glassfish lib folder)
then the client should look like this:
package helloworldprojectclient;
import javax.naming.InitialContext;
import helloworld.ejb.HelloWorld;
public class HelloWorldClient {
public static void main(String[] args) {
try {
InitialContext ic = new InitialContext();
HelloWorld thing = (HelloWorld) ic.lookup("helloworld.ejb.HelloWorld");
System.out.println("It seems it runs: " + thing.outputHelloWorld());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Project Dependency Error in Eclipse 3.8 Web development with EJB 3.0 in WebLogic 12

In Eclipse i have created an EAR Project with EJB Project, EJBClient Project and a WebProject.
I create a EntityBean Person and a SessionBean PersonTask at EJB Project. The Eclipse creates automatic a PersonTaskRemote Interface at EJBClient Project. And a Servlet wird created at the WebProject.
// at EJB Project
#Entity
public class Person {
private int id;
private String name;
...setter and getter
}
//SessionBean
public class PersonTask implements PersonTaskRemote {
Person findPerson(int personId){
do something;
}
And
//In EJBClient Project
//The Interface
#Remote
public interface PersonTaskRemote {
Person findPerson(int personId);
}
By Running, Eclipse get an Error! Because it hat a cycle in the Dependency (Project EJB and Project EJBClient). How can i do?
I had search in google, but in all funded tutorials the Interface in Client hat not the EntityBeans. only something like String sayHello(); functions.
How can i avoid the Problem? Maybe create the local Entities in Client Project for the Interface?
Or get me some tutorials for those cases.
thanks.
Move Person to the EJBClient module. It is clearly part of the client, because it is return value of business method. After that there is no cycle anymore, because EJBClient do not depend about other modules.