schemagen for nested objects without ant task - java

I have the following class structure:
#XmlRootElement
public class A{
private String s;
private B b;
//getter and setter
}
#XmlRootElement
public class B{
private String ss;
//getter and setter
}
How to use schemagen to generate schema for class A ?
I am able to generate schema for class B as:
schemagen B.java
at cmd , but when I use same for class A , i.e.:
schemagen A.java
I got following error:
Problem encountered during annotation processing;
see stacktrace below for more information.
java.lang.NullPointerException
.
.
.
A.java:14: cannot find symbol
symbol : class B
location: class beans.A
public B getB() {
^
A.java:18: cannot find symbol
symbol : class B
location: class beans.A
public void setB(B b) {
^
A.java:22: cannot find symbol
symbol : class B
location: class beans.A
private B b;
^
3 errors

I found the sollution :
We need to specify classpath and all the internal beans also.
Following command worked:
schemagen -cp . A.java B.java

Related

JSP could not find available java class

I used following code to call the java class from the JSP page.
<%String something=com.Package1.PrintInPicture.workingFunction(recentData);%>
I have package named as "com.Package1" as well as class and method named as "PrintInPicture" and "workingFunction(Stirng data)" respectively in that package. This is shown in code below:
package com.package1;
public class PrintInPicture {
static int width, height;
public static String workingFunction(String img_name) throws IOException{
}
But my JSP page is showing following error in the code which I have shown above:
cannot find symbol
symbol: class PrintInPicture
location: package com.Package1
Please, Help me to solve this error.

How can I compile this basic Spring application without IDE?

This is my directory layout:
~ koraytugay$ ls -1 biz/tugay/hellospring/
Bike.java
Car.java
Vehicle.java
VehicleApp.java
VehicleService.java
beans.xml
So I am in the root folder and my .java files are in biz/tugay/hellospring/
Code for VehicleApp:
package biz.tugay.hellospring;
/* User: koray#tugay.biz Date: 29/06/15 Time: 15:16 */
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class VehicleApp {
public static void main(String[] args) {
ApplicationContext applicationContext
= new ClassPathXmlApplicationContext("biz/tugay/hellospring/beans.xml");
VehicleService vehicleService = (VehicleService) applicationContext.getBean("vehicleService");
vehicleService.driver();
}
}
and VehicleService:
package biz.tugay.hellospring;
/* User: koray#tugay.biz Date: 29/06/15 Time: 15:10 */
public class VehicleService {
private Vehicle vehicle;
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
public void driver(){
System.out.println(vehicle.drive());
}
}
Also in my home directory I have the following jar files:
~ koraytugay$ ls -1 *.jar
spring-aop-3.2.5.RELEASE.jar
spring-beans-3.2.5.RELEASE.jar
spring-context-3.2.5.RELEASE.jar
spring-security-core-3.2.5.RELEASE.jar
I tried several variations however I was not successful with any of them. One example:
~ koraytugay$ javac -cp .:/biz/tugay/hellospring biz/tugay/hellospring/VehicleApp.java
biz/tugay/hellospring/VehicleApp.java:4: error: package org.springframework.context does not exist
import org.springframework.context.ApplicationContext;
^
biz/tugay/hellospring/VehicleApp.java:5: error: package org.springframework.context.support does not exist
import org.springframework.context.support.ClassPathXmlApplicationContext;
^
biz/tugay/hellospring/VehicleApp.java:10: error: cannot find symbol
ApplicationContext applicationContext
^
symbol: class ApplicationContext
location: class VehicleApp
biz/tugay/hellospring/VehicleApp.java:11: error: cannot find symbol
= new ClassPathXmlApplicationContext("biz/tugay/hellospring/beans.xml");
^
symbol: class ClassPathXmlApplicationContext
location: class VehicleApp
4 errors
I have the .jar files in the folder I am executing javac. Why the compiler is unable to find ClassPathXmlApplicationContext ?
you either need to specify every jar
java -cp ./spring-aop-3.2.5.RELEASE.jar ; ./spring-beans-3.2.5.RELEASE.jar ;./spring-context-3.2.5.RELEASE.jar ; ./spring-security-core-3.2.5.RELEASE.jar
or use a wild card
java -cp *.jar; /otherpath
but thats only works with java 6 up

How to consider maven dependency in java program compilation via command line

I executed my java file like this:
javac -cp ".:/root/Desktop/karim/software/UIMA/yagogit/yodaqa/gradle/wrapper/gradle-wrapper.jar" LATByFocus.java
which gives error like:
LATByFocus.java:5: package org.apache.uima does not exist
import org.apache.uima.UimaContext;
^
LATByFocus.java:6: package org.apache.uima.analysis_engine does not exist
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
^
LATByFocus.java:7: package org.apache.uima.fit.component does not exist
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
^
LATByFocus.java:8: package org.apache.uima.fit.util does not exist
import org.apache.uima.fit.util.JCasUtil;
^
....
LATByFocus.java:36: cannot find symbol
symbol: class JCasAnnotator_ImplBase
public class LATByFocus extends JCasAnnotator_ImplBase {
^
LATByFocus.java:37: cannot find symbol
symbol : class Logger
location: class cz.brmlab.yodaqa.analysis.question.LATByFocus
final Logger logger = LoggerFactory.getLogger(LATByFocus.class);
^
LATByFocus.java:39: cannot find symbol
symbol : class UimaContext
location: class cz.brmlab.yodaqa.analysis.question.LATByFocus
public void initialize(UimaContext aContext) throws ResourceInitializationException {
^
LATByFocus.java:39: cannot find symbol
symbol : class ResourceInitializationException
......
So I wanted to try considering pom.xml along with jar file in command line - pom.xml
Is it possible?
I am trying to execute these files https://github.com/brmson/yodaqa/tree/master/src/main/java/cz/brmlab/yodaqa/analysis/question
in project : yodaqan

Can't use a Java class in another file

Can't find a solution to this problem.
Guitar2.java:
public class Guitar2
{
private String serialNumber;
public Guitar2(String serialNumber)
{
this.serialNumber = serialNumber;
}
public String getSerialNumber()
{
return serialNumber;
}
}
Inv2.java:
import java.util.List;
import java.util.LinkedList;
public class Inv2
{
private List guitars;
public Inv2()
{
guitars = new LinkedList();
}
public void addGuitar(String serialNumber)
{
Guitar2 guitar = new Guitar2(serialNumber);
guitars.add(guitar);
}
}
Both files are in the same directory, both are 755 and the directory is in the classpath. I get the error message:
[machine]me # directory $ javac Inventory.java
Inventory.java:18: cannot find symbol
symbol : class Guitar
location: class Inventory
Guitar guitar = new Guitar();
^
Inventory.java:18: cannot find symbol
symbol : class Guitar
location: class Inventory
Guitar guitar = new Guitar();
^
2 errors
I read that if a file is in the same directory, classes from it can be used in other files in the same directory without any import statements. What's the problem here?
POST EDIT Output when using the above code:
[me]machine # ricks $ javac Inv2.java
Note: Inv2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
I get the .class files of both .java files.
Run javac Guitar.java
and only then (after it has been compiled and a Guitar.class was created) run javac Inventory.java
Try to compile Guitar.java first. then run your cmd . or try this : javac *.java
Make sure both classes have the same package. Even if they are in the same directory, a different package could cause this problem. Type the same package or use an import and then try compiling with javac *.java

Error using classloader to load groovy class

I am attempting to load a groovy class by name using a classloader, and the class fails to load in the case that the class has a reference to a static inner class in another class.
Inside my groovy class I have the following:
def classLoader = getClass().classLoader
try {
classLoader.loadClass( "com.test.TestClass" )
} catch(Throwable e) {
Sigil.logger.error("Error loading class: $it >> ${e.message}", e)
}
In the above, my groovy file TestClass has a static inner class inside it, that extends a static inner class of another file. When I try to run the above code I get the message:
ERROR [05 Aug 2013 06:53:28,851] (invoke0:?) - Error loading class: com.test.TestClass >> startup failed:
unable to resolve class UserValidity.Validator
# line 85, column 5.
public static class Validator extends UserValidity.Validator{
^
1 error
Has anyone come across any problems dealing with static inner classes and class loading in groovy before? The classes all compile correctly and unit tests run etc. I would have thought that when I try to load the class TestClass explicitly in my classloader, it would also load the other necessary classes from the source tree as needed?
UPDATE:
Here is a snippet of the class that is failing to load:
class TestClass{
//... Other normal class stuff here
public static class Validator extends UserValidity.Validator
#Override
def validate(u) {
def result = super.validate(u)
if(!u.valid ){
result += [isValid:false]
}
result
}
}
}
And this fails as it says it cannot resolve the reference to the UserValidity.Validator, which is also pretty simple:
class UserValidity {
//normal class stuff here
public static class Validator {
def validate(u){
//do validation stuff
result
}
}
}
Both are just regular groovy classes.
UPDATE 2:
If I extract the static inner class UserValidity.Validator out in to a standalone class, and just extend that with the static inner class in TestClass then it appears to work, so definitely seems to be some issue with the parent of the inner class being another inner class

Categories

Resources