I'm following this simple tutorial: https://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example-document-style/?fbclid=IwAR0vxhYrj9MKy1Q28h6luFVJoSxDP4KWBOLEu_v_Ss4uQztmB-9JuYsS4RI and at step 3 it mentions that I should receive the error:
Wrapper class com.mkyong.ws.jaxws.GetHelloWorldAsString is not found.
Have you run APT to generate them?
However, I do not get such error(no error at all) and I'm worried that it is not working as expected.
My classes:
Interface:
package com.soap3sk.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
// Service Endpoint Interface
#WebService
#SOAPBinding(style= Style.DOCUMENT, use= Use.LITERAL) // optional
public interface NoteEndpoint {
//#WebMethod ArrayList<ToDoNote> getNotes();
#WebMethod String getHelloWorldAsString(String name);
}
Implementation:
package com.soap3sk.ws;
import javax.jws.WebService;
#WebService(endpointInterface = "com.soap3sk.ws.NoteEndpoint")
public class NoteEndpointImpl implements NoteEndpoint {
#Override
public String getHelloWorldAsString(String name) {
return "Hello World JAX-WS " + name;
}
}
Publisher:
package com.soap3sk.endpoint;
import javax.xml.ws.Endpoint;
import com.soap3sk.ws.NoteEndpointImpl;
public class NoteEndpointPublisher {
public static void main (String[] args) {
Endpoint.publish("http://localhost:5000/ws/hello", new NoteEndpointImpl());
}
}
Project structure: https://imagizer.imageshack.com/img924/3514/BAuOcl.png
What I also noticed that those 2 .class files(asString and Response that are mentioned in the guide) are not generated anywhere as well. I'm using Eclipse and created a maven project with the quickstart archetype. Runnning it as a standard java application.
I can access the wsdl file going here: http://localhost:5000/ws/hello?wsdl and the I can see getHelloWorldAsString and getHelloWorldAsStringResponse there, but they are nowhere to be seen in my project and no error is thrown that they could not be found as mentioned in the guide that it should.
I also tried downloading the sample project and deleting the .java files that should be required, but it is stil the same(no error, not asking to create those classes).
I would be very grateful if someone could help. Thank you.
EDIT
I found a similiar question here: Java web service not giving error message Could someone explain his answer? Is the creation of those two classes not necessary?
you're trying to replicate a situation reported almost 10 years ago. Don't you want to try a newer tutorial like the following:
https://www.baeldung.com/jax-ws
https://spring.io/guides/gs/producing-web-service/
Related
It's as the title says. I'm trying to call methods defined in another Java project. Is there a way I can do that? I tried import statements but that didn't work.
EDIT:
So here is what is sitting in the code now in terms of imports:
enter image description here
and here are some of the functions I want to call that are in the other project:
enter image description here
What I've tried is:
import com.example.cs320EthicsPlayer.api.*
but that doesn't work it just says import can't be resolved.
Where the 2 projects are located:
enter image description here
I'm not too familiar with mvn directories but we are using maven. The methods I want to call are from the cs320EthicsPlayer folder (project) and the file I'm calling it from is from partyinthebackend (another project). I haven't called on the other project at all, and that's what I'm trying to figure out.
Class Path for the file I'm trying to call the functions from:
enter image description here
Let's say we have a class Test inside a package com.example :
package com.example;
public class Test {
public static String getHalloWorld (){
return "Hello world";
}
}
All we need if we want to use our class Test in another package is to use import like that
import com.example.Test;
class OtherPackage {
public static void main(String[] args) {
String geeting = Test.getHalloWorld();
System.out.println(geeting);
}
}
You should remember anything you want to use in another package it should be public.
So just check where is the method, which package and class include the method you are trying to import.
Let's fix your problem now:
try
import com.example*
Now you import the whole package, but you should remember you can import and use just the public method from the package example.
Update:
I see you have updated your question again, and you want to use maven, I think that will answer your question :
Java project dependency on another project
I hope that answers your question.
If it is in the same project but different package you can just doing
import package name...
If it is a complete different project you can't import them. You need to re-insert the methods.
I have 2 Projects in Eclipse:
The first one is a maven project using google AdWords API dependencies and the second one is a dynamic web project. I have imported the first project by clicking on the second -> import -> Existing Maven Projects -> MyFirstProjectFolder -> Finish. It made a new pom.xml.
I've used a class from the first project in the second by importing it and running a method of it and i get an error: java.lang.NoClassDefFoundError.
I'm not a professional java programmer but as I understood the second project doesn't get the class but in my eclipse editor I have no errors or mistakes.
I hope I was precise enough. Thank you in advance.
package com.adwordsfeatures;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import url_checker.*;
#Path("/hello")
public class ServerService {
#GET
#Produces(MediaType.TEXT_PLAIN)
#Path("first")
public String hello(){
return "Hi everyone";
}
#GET
#Path("go")
public String go(){
runProgramMethod();
return "<p1>Programm running</p1>";
}
private void runProgramMethod() {
MainPauserMethod runner = new MainPauserMethod();
}
}
this is the code in the second Project and the class i'm trying to use from the first project is the MainPauserMethod (i know it's a class it's just a test i'll change the name) and it's from the package url_checker.
I'm checking out the Play! Framework, using Java (don't want to learn a new framework and a new language at the same time - I'll incorporate Scala as I learn that), and so far it's awesome.
I'm having a bit of difficulty with forms though. I'm still stuck on the first part here and, as far as I understand, I somehow need to get an instance of FormFactory or something related, however I have no idea in which package it might be located, or whether formFactory is also another magic method (like ok).
Any pointers would be appreciated!
EDIT Here's my code:
package controllers;
import com.google.inject.Inject;
import play.data.FormFactory;
import play.api.data.Form;
import play.mvc.*;
public class User extends Controller {
#Inject
FormFactory form;
final static Form<model.User> userForm = form(model.User.class);
public Result post() {
model.User user = userForm.bindFromRequest().get();
return ok("The form was received!: " + user);
}
}
The play.data package doesn't exit for me. Maybe I did an incorrect install? To be clear, I did start this project from IntelliJ
One issue is that your form should not be static as there is no way to initialize it before FormFactory is injected.
According to docs this call
Form<model.User> userForm = form(model.User.class);
should be
Form<model.User> userForm = form.form(model.User.class)
as form is method of FormFactory.
If the package is missing from class path its some configuration issue or wrong play version. A working project can be usually obtained through activator.
Can someone please correct me, I've found this example online and bunch of others not working, this particular example throws the following error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/SetUtils
at org.quartz.JobDetail.<init>(JobDetail.java:85)
at tralala.org.xml.CronSchedule.<init>(CronSchedule.java:13)
at tralala.org.xml.CronSchedule.main(CronSchedule.java:20)
Here is the code :
CronJob.java
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class CronJob implements Job {
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("PRINT SOME TEXT LINE");
}
}
CronSchedule.java
import org.quartz.CronTrigger;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.JobDetail;
public class CronSchedule {
public CronSchedule ()throws Exception {
SchedulerFactory sf=new StdSchedulerFactory();
Scheduler sched=sf.getScheduler();
JobDetail jd=new JobDetail("job1","group1",CronJob.class);
CronTrigger ct=new CronTrigger("cronTrigger","group2","0 0/1 * * * ?");
sched.scheduleJob(jd,ct);
sched.start();
}
public static void main(String args[]){
try{
new CronSchedule();
}catch(Exception e){}
}
}
I just wanna run(that is actually works) any example of quartz .. I've been searching for some time now and every example either has compile error or like this one(rare one) throws an error. I just wanna run it this one or any .. just to get some inside with a concrete example. I've been reading http://www.opensymphony.com/quartz/wikidocs/TutorialLesson1.html, the examples don't compile .. any suggestions ? tnx
The error just shows that you don't have the class org.apache.commons.collections.SetUtils in your class path. So you should ensure that. You can download the library from here.
Then extract the download file. You should see a file commons-collections-3.2.1.jar. You just place that file in your class path. OR run it with the option '-cp commons-collections-3.2.1.jar'.
Add to the class path the library containing the SetUtils class.
You can find it here.
You should add commons-collections (v3.1) to you classpath. It's also bundled in the Quartz distribution.
It will probably be much easier for you if you start with the examples that come bundled with in the Quartz distribution archive. They are in the examples subdirectory and for each example there's a script to run it (alongside the ant-based compilation script of course). Study these scripts to see how everything fits together. As Quartz comes bundled with all needed dependencies you should be able to run the examples without downloading whatsoever.
Please tell me how to write wsdl file of service developed in java. For example:
package fromjava.server;
import javax.jws.WebService;
import javax.jws.WebMethod;
#WebService
public class AddNumbersImpl {
#WebMethod(action="addnumbers")
public int addNumbers(int number1, int number2) {
return (number1+number2);
}
}
this is a web service....so what will be the corresponding wsdl file? if u guys have any tutorial then please help me out.
You can use axis2's java2wsdl to generate the wsdl from a java interface.
see http://ws.apache.org/axis/java/user-guide.html#Java2WSDLBuildingWSDLFromJava