I'm trying to execute the wsgen command to create a Web Service. My command lines are:
PATH=%path%;C:\Program Files\Java\jdk1.6.0_24\bin
wsgen -cp ".\war\WEB-INF\classes" -wsdl -keep -r ".\war" -d ".\war\WEB-INF\classes" - s ".\war" "com.example.prototipo21.Greeting"
And this error appears:
warning: Cannot find annotation method 'valueStrategy()' in type 'javax.jdo.annotations.Persisten': class file for javax.jdo.annotations.Persistent not found.
error: Could not find class file for com.example.prototipo21.Greeting
1 error
1 warning
error: compilation failed, errors should have been reported
I think the problem could be I'm integrating a Datastore Application in a Web Service application so my class has different annotations. For example:
#WebService
public class Greeting {
#PrimaryKey
#Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
#Persistent
private User author;
...
#WebMethod
public Key getKey() {
return key;
}
#WebMethod
public User getAuthor(){
return author;
....
you know what I mean?? Any idea will be very useful!! Thanks!
Those are my commands and the entire trace:
c:\Users\...\Desktop\....\Eclipse\Prototipo_21>PATH=%pa
th%;C:\Program Files\Java\jdk1.7.0_03\bin
c:\Users\...\Desktop\....\Eclipse\Prototipo_21>wsgen -c
p ".\war\WEB-INF\classes" -wsdl -keep -r ".\war" -d ".\war\WEB-INF\classes" -s "
.\war" "com.example.prototipo21.Greeting"
warning: The apt tool and its associated API are planned to be
removed in the next major JDK release. These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model. Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.
.\war\WEB-INF\classes\com\example\prototipo21\Greeting.class: warning: Cannot fi
nd annotation method 'valueStrategy()' in type 'Persistent': class file for java
x.jdo.annotations.Persistent not found
warning: unknown enum constant IdGeneratorStrategy.IDENTITY
reason: class file for javax.jdo.annotations.IdGeneratorStrategy not found
error: Could not create declaration for annotation type javax.jdo.annotations.Pr
imaryKey
error: Could not create declaration for annotation type javax.jdo.annotations.Pe
rsistent
Problem encountered during annotation processing;
see stacktrace below for more information.
com.sun.tools.internal.ws.processor.modeler.ModelerException: modeler error: Cla
sses annotated with #javax.jws.WebService must have a public default constructor
. Class: com.example.prototipo21.Greeting
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAP.o
nError(WebServiceAP.java:229)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisi
tor.isLegalImplementation(WebServiceVisitor.java:515)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisi
tor.shouldProcessWebService(WebServiceVisitor.java:322)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisi
tor.visitClassDeclaration(WebServiceVisitor.java:113)
at com.sun.tools.apt.mirror.declaration.ClassDeclarationImpl.accept(Clas
sDeclarationImpl.java:113)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAP.b
uildModel(WebServiceAP.java:319)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAP.p
rocess(WebServiceAP.java:260)
at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.
process(AnnotationProcessors.java:84)
at com.sun.tools.apt.comp.Apt.main(Apt.java:480)
at com.sun.tools.apt.main.AptJavaCompiler.compile(AptJavaCompiler.java:2
70)
at com.sun.tools.apt.main.Main.compile(Main.java:1127)
at com.sun.tools.apt.main.Main.compile(Main.java:989)
at com.sun.tools.apt.Main.processing(Main.java:113)
at com.sun.tools.apt.Main.process(Main.java:103)
at com.sun.tools.apt.Main.process(Main.java:85)
at com.sun.tools.internal.ws.wscompile.WsgenTool.buildModel(WsgenTool.ja
va:207)
at com.sun.tools.internal.ws.wscompile.WsgenTool.run(WsgenTool.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:120)
at com.sun.tools.internal.ws.WsGen.main(WsGen.java:42)
error: compilation failed, errors should have been reported
The error has no issues with the code you have written. The issue is with the classpath. If you examine the error you can distinctly see:
Could not find class file for com.example.prototipo21.Greeting1
Fix your classpath so that the class is available to wsgen and you might get a step ahead and stumble in next set of errors :) Good luck
I was having the same error. The reason why you are getting this error is that you have to give wsgen a reference to the libraries that GAE are using as well.
Just modify the classpath to include the other jar files. Note that in Unix we use colon ":" to separate directories and in Windows we use semi-colon ";".
(Just change the directory path accordingly)
class=com.sample.MyWebService
clpth='./war/WEB-INF/classes:/Applications/eclipse_jee/plugins/com.google.appengine.eclipse.sdkbundle_1.7.0/appengine-java-sdk-1.7.0/lib/opt/user/datanucleus/v2/jdo-api-3.1-SNAPSHOT-20110926.jar:/Applications/eclipse_jee/plugins/com.google.appengine.eclipse.sdkbundle_1.7.0/appengine-java-sdk-1.7.0/lib/user/appengine-api-1.0-sdk-1.7.0.jar'
resourcedir='./war'
outsourcedir='./src'
outdir='./war/WEB-INF/classes'
wsgen -cp "$clpth" -wsdl -keep -r "$resourcedir" -d "$outdir" -s "$outsourcedir" $class
Related
I am using JDK11. Below is my sample class -
public class SayHi {
public static void main(String[] args) {
System.out.println("Hi There");
}
}
I executed the above class with command "java filename.java" for below scenarios
ColumnA -> Class declared as public?
ColumnB -> File name same as class name?
ColumnA ColumnB Result
Yes Yes Yes
No Yes Yes
*Yes No Yes
No No Yes
For all the scenarios, the command executed successfully and I got the result. I get compile-time error for the "Yes-No" case, if I run the "javac" command on the file name.
Why I am not getting the compile-time error when I am executing "java" command on the file name?
I have multiple public classes in a single code file. I am able to execute the file using "java filename.java" command. What I am missing with the compile-time issues when running the file with "java" command. Please help me on this.
The answers to all your questions can be found in JEP 330. I believe the following excerpts provide answers to your questions.
the first class found in the source file is executed
The source file should contain one or more top-level classes, the first of which is taken as the class to be executed
The compiler does not enforce the optional restriction defined at the end of JLS ยง7.6, that a type in a named package should exist in a file whose name is composed from the type name followed by the .java extension
In other words, when you compile a java source code file with javac, the source code file must contain a single, "public" class whose name matches the name of the file. But when you run a java source code file using the java command, the above restriction does not apply.
The class to be executed is the first top-level class found in the source file. It must contain a declaration of the standard public static void main(String[]) method.
I am trying to run an implementation a jason code that is using some Internal Actions. The interpreter is showing that it was not possible to find the "java" code of the internal action, as showed:
Server running on http://191.36.8.42:3272
[aslparser] [peleus.asl:29] warning: The internal action class for 'org.soton.peleus.act.plan(Goals)' was not loaded! Error:
java.lang.ClassNotFoundException: org.soton.peleus.act.plan
[aslparser] [peleus.asl:42] warning: The internal action class for 'org.soton.peleus.act.isTrue(H)' was not loaded! Error:
java.lang.ClassNotFoundException: org.soton.peleus.act.isTrue
[peleus] Could not finish intention: intention 1: +des([on(b3,table),on(b2,b3),on(b1,b2)])[source(self)] <- ... org.soton.peleus.act.plan(Goals); !checkGoals(Goals); .print("Goals ",Goals," were satisfied") /
{Goals=[on(b3,table),on(b2,b3),on(b1,b2)]}Trigger: +des([on(b3,table),on(b2,b3),on(b1,b2)])[noenv,code(org.soton.peleus.act.plan([on(b3,table),on(b2,b3),on(b1,b2)])),code_line(29),code_src("peleus.asl"),error(action_failed),error_msg("no environment configured!"),source(self)]
[peleus] Adding belief clear(table)
This mas2j file is as following:
MAS peleus {
infrastructure: Centralised
agents:
peleus;
}
Part of agent code (written by Felipe Meneguzzi) is showed bellow:
//The next line is line 28
+des(Goals) : true
<- org.soton.peleus.act.plan(Goals);
!checkGoals(Goals);
.print("Goals ",Goals," were satisfied").
+!checkGoals([]) : true <- true.
//The next line is line 40
+!checkGoals([H|T]) : true
<- .print("Checking ", H);
org.soton.peleus.act.isTrue(H);
!checkGoals(T).
I guess it is about the folder structure, how to set up Jason to search for java files in specific locations?
The folders structure is like this:
Peleus\src\org\soton\peleus for java files
Peleus\examples for mas2j and asl tested project
It all depends on how you are executing the application.
If you are using java, the CLASSPATH should be defined to include the missing classes.
if you are using jason script (that uses Ant), the .mas2j file should include the class path as well.
More on that in the FAQ. Notice that CLASSPATH is where .class files are found, not .java source code files. The error regards a missing class, not a missing source code.
I have a class in Java which looks like this:
package com.charandeepmatta.keywords;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;
#RobotKeywords
public class SampleKeywords {
#RobotKeyword
public void printToErrorStream() {
System.err.println("!!! Hello from keyword developed in java ...");
}
}
And my test case looks like this
*** Settings ***
Library org.robotframework.javalib.library.AnnotationLibrary /**.class
*** Test Cases ***
Keyword defined in java class can print to error stream
Print To Error Stream
When I try to run it on RIDE it gives me the following error
[ ERROR ] Error in file 'C:\Users\BFerreira\git\robotframework-maven-project\src\main\robot\suite\OwnDevelopedKeywordTestCase.txt':
Importing test library 'org.robotframework.javalib.library.AnnotationLibrary' failed:
ImportError: No module named org.robotframework.javalib.library
Traceback (most recent call last):
None
PYTHONPATH:
C:\Python27\lib\site-packages\robot\libraries
C:\Python27\lib\site-packages
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages\wx-2.8-msw-unicode
.
C:\Users\user1\git\robotframework-maven-project\src\main\robot\suite
Everything is in the same classpath, can anyone help?
From the looks of your output, you are not executing with jybot/Jython. Jython is required to load Java classes in a Python interpreter. Here is what the output would look like if you were:
PYTHONPATH:
C:\apps\Python27\Lib\site-packages
C:\apps\jython2.5.3\Lib\site-packages\setuptools-0.6c11-py2.5.egg
C:\apps\jython2.5.3\Lib\site-packages\pip-1.2.1-py2.5.egg
C:\apps\jython2.5.3\Lib
__classpath__
__pyclasspath__/
C:\apps\jython2.5.3\Lib\site-packages
.
c:\ws\local
CLASSPATH:
C:\apps\jython2.5.3\jython.jar
A word of caution: if you run the Robot Framework jar (e.g. java -jar robotframework-2.5.3.jar ...) as some examples suggest, all classpath settings are ignored. You would have to put all your dependencies in one jar for that way to work...
I am new to pig. I wrote a UDF in pig and used it in my pig script. But it gives following error
ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve UserDefined.PartsOfSpeech using imports: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.]
Here is my UDF code
public String exec(Tuple input) throws IOException {
//my code here
}
Here is my pig script
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE UserDefined.PartsOfSpeech(input);
In the above code UserDefined is my package name and PartsOfSpeech is my class name
The error message says that Pig cannot find UserDefined.PartsOfSpeech.
What package declaration does PartsOfSpeech.java have at the top of the file?
If the package declaration is package com.my.company; try this instead:
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE com.my.company.PartsOfSpeech(input);
That is, replace UserDefined.PartsOfSpeech(input) with com.my.company.PartsOfSpeech(input) since the UDF is located in the package com.my.company.
Also, consider using the DEFINE keyword in your Pig script so you don't need to repeat com.my.company every time you use PartsOfSpeech.
DEFINE PartsOfSpeech UserDefined.dist.PartsOfSpeech();
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE PartsOfSpeech(input);
There is more information about DEFINE in Chapter 5 of Alan Gates' Programming Pig: http://chimera.labs.oreilly.com/books/1234000001811/ch05.html#udf_define.
Here is an example of DEFINE from Gates' book:
--define.pig
register 'your_path_to_piggybank/piggybank.jar';
define reverse org.apache.pig.piggybank.evaluation.string.Reverse();
divs = load 'NYSE_dividends' as (exchange:chararray, symbol:chararray,
date:chararray, dividends:float);
backwards = foreach divs generate reverse(symbol);
Before compiling your UDF(java class) make sure you have mentioned package name properly. for example if you have mentioned package name-
package com.pig.udf;
It means you need to take care of directory in your linux box as well.
you can follow below mentioned steps to create jar -
Create directory using
mkdir -p com/pig/udf
Create your java class with package com.pig.udf
Compile your java source code using command
javac -cp /usr/lib/pig-0.12.0.2.0.6.0-76.jar YourClass.java
Then go to the directory where you want to create jar for now -
cd ../../..
Now create jar using below command
jar -cvf yourJarName.jar com/
Register the jar in your script using keyword "register" followed by path of the jar
Now use your jar with keyword com.pig.udf.YourJavaClassName
for your scenerio -
REGISTER /home/bigdata/NetBeansProjects/UserDefined/dist/UserDefined.jar
a = load '/user/bigdata/json' using TextLoader() as (input:chararray);
b = foreach a GENERATE com.pig.udf.PartsOfSpeech(input);
I am executing Drools rule through Mockito test. The rule fails at run time reporting the error with a line number of a java file having some long arbitrary name. It seems that Drools generates java files on the fly and injects into JVM. But when I search those files on my disc I don't find any. Is there a way I could store them on my disc?
Got the solution:
You can dump the Drools generated java files in two ways.
1) Through command line:
-Ddrools.dump.dir="target/dumpDir"
e.g. I use maven command to execute the rule so it would be
mvn -Ddrools.dump.dir="target/dumpDir" -Dtest=DroolsRuleTest test
2) Through the API
public class FileKnowledgeBaseFactory implements KnowledgeBaseFactory {
private Log log = LogFactory.getLog(FileKnowledgeBaseFactory.class);
public KnowledgeBase load(String drlFullFilename) {
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(DumpDirOption.get(new File("target/dumpDir")));
KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
....
....
}
}