call method java from a maven project in eclipse - java

I have two maven projects "Bonita-engine"and "activity-engine". these projects are the code source of two BPM engine. My project is to find the common method of these two engine code sources.So I create an API Java to call this Java method.
as these methods are on a different project I can not call this method. in fact, I added this two project to the library of my API Java but it doesn't work.
call method getDescription() from bonita-engine maven project
* Copyright (C) 2015 BonitaSoft S.A.
package org.bonitasoft.engine.bpm.process.impl.internal;
import java.util.Date;
import org.bonitasoft.engine.bpm.internal.NamedElementImpl;
import org.bonitasoft.engine.bpm.process.ProcessInstance;
/**
* #author Baptiste Mesta
* #author Matthieu Chaffotte
* #author Celine Souchet
*/
public class ProcessInstanceImpl extends NamedElementImpl implements ProcessInstance {
#Override
public String getDescription() {
return description;
}
}
call method getDescription() from activiti-engine maven project
package org.activiti.engine.impl.persistence.entity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.impl.bpmn.data.IOSpecification;
import org.activiti.engine.impl.context.Context;
public class ProcessDefinitionEntityImpl extends AbstractEntity implements ProcessDefinitionEntity, Serializable {
public ProcessInstanceImpl(final String name) {
super(name);
}
public String getDescription() {
return description;
}
}
API JAVA : call the common method from the two maven project
import org.activiti.bpmn.model.*;
import org.bonitasoft.engine.bpm.process.impl.internal.* ;
import org.bonitasoft.engine.bpm.*;
import java.util.*;
import java.util.Date;
import org.bonitasoft.engine.bpm.internal.*;
import org.bonitasoft.engine.bpm.process.* ;
public class apicommon {
public activitiProcess = new ProcessDefinitionEntityImpl() ;
public String name;
public bonitaProcess = new ProcessInstanceImpl(name) ;
public enum bpm {
activiti , bonita
}
bpm chose ;
public apicommon() {
}
public String getProcessDescription() {
if(chose==bpm.activiti){
return activitiProcess.getDescription() ;
}else if(chose==bpm.bonita){
return bonitaProcess.getDescription();
}
}
i import the package "org.bonitasoft.engine.bpm.process.impl.internal" and the package "org.activiti.engine.impl.persistence.entity" but i can not get access to ProcessInstanceImpl method and ProcessDefinitionEntityImpl method !

#sara, you have to add the 2 projects to the build path of the API java(api common).
Right click on the (api common) java project => Build path => Configure Build Path
Click on the projects tab
Click Add button
add your project1 (bonita) by checking the box next to it
Again add project2 (activiti-engine) usign the same method
Click Apply and OK to close the dialog.
Now your imports should be working.
Edit:
You have not been clear about which import is the problem. More information is necessary to get to the root of the problem.
As regarding the import error, you can Ctrl + click the offending import. This will take you to a page Source Not Found and a button labelled Attach Source. Click the button to search for the location of what I am suspect is an external jar.

Related

Keep getting error "Unable to implement Repository method: RepoClass.updateAll(Iterable arg0). No possible implementations found."

Using Micronaut data v3, I created the following simple classes:
MyEntity.java
package test;
import io.micronaut.data.annotation.GeneratedValue;
import io.micronaut.data.annotation.Id;
import io.micronaut.data.annotation.MappedEntity;
#MappedEntity
public class MyEntity {
#id
#GeneratedValue(GeneratedValue.Type.AUTO)
Long id;
String name;
}
MyRepo.java:
package test;
import io.micronaut.data.jdbc.annotation.JdbcRepository;
import io.micronaut.data.model.query.builder.sql.Dialect;
import io.micronaut.data.repository.CrudRepository;
#JdbcRepository(dialect = Dialect.MYSQL)
public interface MyRepo extends CrudRepository<MyEntity, Long> {
}
The project can build without above 2 classes. Once I add these 2 classes, I got the error
java: Unable to implement Repository method: MyRepo.updateAll(Iterable arg0). No possible implementations found.

Kotlin to java conversion DefaultConstructorMarker is not public in kotlin.jvm.internal

I Downloaded a kotlin file from github and wanted to convert it to a java file. I did this by Tools>Kotlin>Show kotlin ByteCode and then Decompiling. The Kotlin File is below:
package io.pokemon.core
import io.pokemon.model.Card
import io.pokemon.util.random.Randomiser
import io.pokemon.viewmodel.Round
class RoundFactoryImpl(private val randomiser: Randomiser) : RoundFactory {
override fun buildRound(cards: List<Card>): Round = Round()
}
After Copying the Decompiled kotlin Code into a java file I got the error: DefaultConstructorMarker is not public in kotlin.jvm.internal; cannot be accessed from outside package.
I attempted to fix this by adding the code inside DefaultConstructorMarker However this failed to fix the error.
package io.pokemon.core;
import io.pokemon.model.Card;
import io.pokemon.util.random.Randomiser;
import io.pokemon.viewmodel.Round;
import java.util.List;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
#Metadata(
...
)
public final class RoundFactoryImpl implements RoundFactory {
private final Randomiser randomiser;
#NotNull
public Round buildRound(#NotNull List cards) {
Intrinsics.checkParameterIsNotNull(cards, "cards");
return new Round((List)null, (Card)null, 3, (DefaultConstructorMarker)null);
}
public RoundFactoryImpl(#NotNull Randomiser randomiser) {
super();
Intrinsics.checkParameterIsNotNull(randomiser, "randomiser");
this.randomiser = randomiser;
}
}

is there any way of replace this code of this way?

I' am trying to replace this code:
public void doThing(){
if(User.getInstance().isLoggin()){
.....
}
}
by this
#withUser
public void doThing(){
....
}
I saw about the interceptors and annotation, but I cannot do it.
Is this possible?
It is absolutely possible. Project Lombok provides the exact feature what you are looking for. You just need to create your own annotation by extending EclipseAnnotationHandler or JavacAnnotationHandler depending upon your requirement.
A sample annotation handler (WithUser) is given below for reference. If used on method, the entire method will become enclosed by if(false){...} block. Replace false with your own expression on Handler (HandleWithUser.java).
#WithUser
public void doThing(){
System.out.println("Hello World");
}
After annotation processing
public void doThing(){
if (false){
System.out.println("Hello World");
}
}
Setup Project Lombok
git clone https://github.com/rzwitserloot/lombok.git
cd lombok
ant eclipse
Open the Lombok project on Eclipse and create the following files.
WithUser.java
package lombok;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
#Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
#Retention(RetentionPolicy.SOURCE)
public #interface WithUser {
}
HandleWithUser.java
package lombok.javac.handlers;
import static lombok.javac.handlers.JavacHandlerUtil.setGeneratedBy;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.IfStatement;
import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCIf;
import com.sun.tools.javac.tree.JCTree.JCLiteral;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
import org.eclipse.jdt.internal.compiler.ast.FalseLiteral;
import lombok.WithUser;
import lombok.core.AnnotationValues;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
import lombok.javac.JavacTreeMaker;
#ProviderFor(JavacAnnotationHandler.class)
public class HandleWithUser extends JavacAnnotationHandler<WithUser>{
#Override
public void handle(AnnotationValues<WithUser> annotationValues, JCAnnotation ast, JavacNode annotationNode) {
JavacNode annotation = annotationNode.up();
JCMethodDecl method = (JCMethodDecl)annotation.get();
List<JCStatement> contents = (List<JCStatement>) method.body.stats;
JCTree source = annotation.get();
JavacTreeMaker maker = annotationNode.getTreeMaker();
JCLiteral falseLiteral = maker.Literal(false);
JCIf ifStatement = maker.If(falseLiteral, maker.Block(0, contents), null);
Context context = annotationNode.getContext();
JCStatement ifBlock = setGeneratedBy(ifStatement, source, context);
method.body.stats = List.of(ifBlock);
annotation.rebuild();
}
}
Generate lombok.jar
ant dist
Test
Make sure you are including lombok.jar in classpath
javac -cp lombok.jar Test.java
For more info, visit https://projectlombok.org/contributing/contributing

Processing with JBox2d Hellow World issue

Using eclipse, I'm trying to write a simple hello world program in processing that simply draws a rectangle on the screen then has gravity drop it as seen in this Tutorial.
The problem is that when I try to import the p5 package, it's not resolving so I can't declare my Physics object. I tried two things.
Download the zip, unzip it, then import the 3 jars (library, serialization, & testbed)
a. import org.jbox2d.p5.*; doesn't resolve but the others do
b. Physics physics; doesn't resolve
Download the older standalone testbed jar then import it
a. Physics physics; doesn't resolve;
Here is basically where I'm starting
import org.jbox2d.util.nonconvex.*;
import org.jbox2d.dynamics.contacts.*;
import org.jbox2d.testbed.*;
import org.jbox2d.collision.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
import org.jbox2d.p5.*;
import org.jbox2d.dynamics.*;
import processing.core.PApplet;
public class MyFirstJBox2d extends PApplet {
Physics physics;
public void setup() {
size(640,480);
frameRate(60);
initScene();
}
public void draw() {
background(0);
if (keyPressed) {
//Reset everything
physics.destroy();
initScene();
}
}
public void initScene() {
physics = new Physics(this, width, height);
physics.setDensity(1.0f);
physics.createRect(300,200,340,300);
}
}
Everything is in the ZIP file from the tutorial.
All classes in org.jbox2d.p5 are contained in boxwrap2d.jar. Also add Physics.java (plus the other dependent java files) to your source path.

Play Framework Does Not Create Models

I just downloaded the play framework from their site and am working through this tutorial.
I've noticed the framework creates the folders app/controllers and app/views, but not a models folder. I created it manually and added Task.java to it. When I get to the section entitled "Rendering the first page" and open localhost:9000/tasks I get a compilation error that says package play.models does not exist. Here is what my Task.java looks like:
package models;
import java.util.*;
public class Task {
public Long id;
#Required
public String label;
public static List<Task> all() {
return new ArrayList<Task>();
}
public static void create(Task task) {
}
public static void delete(Long id) {
}
}
Here is application.java, the file generating the compilation error:
package controllers;
import play.*;
import play.mvc.*;
import views.html.*;
import play.data.*;
import play.models.*; // COMPILATION ERROR: "package play.models does not exist"!
public class Application extends Controller {
static Form<Task> taskForm = Form.form(Task.class);
public static Result index() {
//return ok(index.render("Your new application is ready."));
return redirect(routes.Application.tasks());
}
public static Result tasks() {
return ok(views.html.index.render(Task.all(), taskForm));
}
public static Result newTask() {
return TODO;
}
public static Result deleteTask(Long id) {
return TODO;
}
}
I believe it's supposed to be import models.Task; as opposed to import play.models.*;
That's quite confusing (IMHO) step in this tutorial, instead scroll down to Persist the tasks in a database section which describes preparing a model to cooperate with DB :) (it extends Model class, uses proper annotations, etc)
As you recognized it yet, you need to create a models package yourself.
Also as cYn wrote: you should import models like models.SomeModel into your controller
You are correct HukeLau_DABA , the Play will not create the models package for you. you have to create it.
I got these imports in my Application controller class. I got this sample play application running.
import play.api._
import play.api.mvc._
import play.api.data.Form
import play.api.data.Forms._
import models.Task
and another thing in Eclipse is it will not import the necessary imports automatically.
it is bit pain now, once the IDE support get better I hope this will change.

Categories

Resources