Cannot deploy in the Modeler while deploy in Eclipse works fine

3
Hi, Today I worked on some Java-actions to connect to 3rd party systems... While development, I started the Mendix-runtime in Eclipse (using Ctrl + F11), after which I could use my application in the browser. But, now I have a problem - When I run the project in Eclipse, the application (including the java-action) works fine - When I run (F5) in the modeler, I get a compile error - When I try to make a deployment archive, I also get the error When I delete the java-code in my java-action (between the usercode placeholders), the problems are gone, but obviously that is not what I want... Buildfile: D:[LOCAL_PATH]\build.xml error: compile: [javac] Compiling 1 source file to D:\[LOCAL_PATH]\lib\bin [javac] com\blabla\bla2bla2\model\Order.class(com\blabla\bla2bla2\model:Order.class): warning: Cannot find annotation method 'name()' in type 'javax.persistence.Table': class file for javax.persistence.Table not found [javac] com\blabla\bla2bla2\model\Product.class(com\blabla\bla2bla2\model:Product.class): warning: Cannot find annotation method 'name()' in type 'javax.persistence.Table' [javac] D:\bla2bla2\javasource\order_management\actions\Create_New_Order.java:69: type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object [javac] int peProductQuantity = element.getValue(this.getContext(), [javac] ^ [javac] 1 error [javac] 2 warnings BUILD FAILED D:\[LOCAL_PATH]\deployment\build.xml:64: Compile failed; see the compiler error output for details. Total time: 2 seconds -->At first sight I would say, there is a problem in the java-code I execute (or in the jar-files that I have put in the userlib folder). But when run in Eclipse the problems are gone (which makes me think that the java-action and jar-files are correct). So I wonder what the problem is!
asked
4 answers
4

This problem comes from a difference between the Sun and Eclipse compiler (the latter is the better and faster one in my experience)

There are three solutions

  1. Add a bunch of extra casts to your code, so the type inference will be easier for the compiler. I think this might already solve the problem:

    int peProductQuantity = (int) ((Long) element.getValue(this.getContext(), "Quantity"));

  2. Always compile using eclipse

  3. Put this javacode in a seperate class, and package that class in a jar (that can be done quite easily with eclipse) which you store in the userlib. This way the eclipse compiler compiles the code, and it is never done by the Sun compiler

BTW, this problem is not caused by the third party libraries

answered
4

The compile error that you get when running from the Modeler appears to be a bug in the Oracle Java compiler. Eclipse uses its own compiler that does not contain that bug.

The solution is to change your Java code to work around the compiler bug.

See this page for more information about the bug and how to work around it.

answered
1

It looks like the modeler can't find the jar you're referencing. Where exactly did you put the jar file? It should be under myprojectdir/userlib (and not under myprojectdir/deployment/userlib/)

answered
1

Dear Benny,

Thanks for your reaction. My question would then be: is the code that causes the problem in my java-action or in the jar-files I reference?

I'm not really (or really not :-) ) a java-developer, but produced this code. Here I indicated which line causes the compilation-error. Should this code-part be changed, or should my java-colleagues change their code?

// get orderlines of the order
List<IMendixObject> result = Core.retrieveXPathQuery(this.getContext(),
                "//Order_Management.OrderLines[Order_Management.OrderLines_Order='"
                      + this.jOrder.getGUID() + "']");

// define iterator
Iterator<IMendixObject> iterator = null;

iterator = result.iterator();

// loop through orderLines  
while (iterator.hasNext()) {

IMendixObject element = iterator.next();

long peProductQuantity;
peProductQuantity = 0;

/*the lines below work in both mendix and eclipse!!*/             
ILogNode logger = Core.getLogger("TestQuantity");
logger.info("Quantity:  "+ element.getValue(this.getContext(), "Quantity"));

//when the line below is commented out, I can compile in the modeler, if not, I can't
peProductQuantity = element.getValue(this.getContext(), "Quantity");

// Fill in product details
Product product = new Product();
product.setQuantity((int) peProductQuantity);

order.getProducts().add(product);

}

If there is an alternative for the code above (that works around the problem), I'm glad to hear; if not, I will ask the guys of the 3rd party system I connect with.

answered