I need to execute java code in my BPEL application, i selected java Embeding from pallate and in code snippet i wrote some lines as
System.out.println("some information");
while deployment it showed me error as "failed to compile generated BPEL classed for BPEL process "Processname" of composite" class path setting is incorrect.
please let me know how to set classpath in BPEL.
one more thing i have not created any class yet, as I am executing only snippet i have written.
Executing java code is BPEL never a good and idea will most certainly break the default build.xml generated by Jdev. However if you do want to use java code, just make sure that all the class names are their fully qualified names. This link may help.
Related
Is it possible to dynamically instrument Java bytecode without a Java agent? I have instrumented bytecode using a Java agent before, doing something akin to this:
ClassFileTransformer myTransformer = new Transformer();
instrument.addTransformer(myTransformer, true);
instrument.retransformClasses(classInstance);
instrument.removeTransformer(myTransformer);
But is this possible without the use of a Java agent? What I would like to do is call a method which will do my instrumentation at any given time after the JVM is running, just without the use of an agent.
The only ways to perform byte code transformation without an instance of an Instrumentation implementation would be
Custom class loaders which can change the bytes before calling defineClass (which is limited to classes loaded through that loader)
Calling MethodHandles.Lookup.defineClass with modified bytes even before the class has been loaded, which works on the widespread JVMs with lazy loading, but is limited to your own module or modules opened to your module
Neither approach can change already loaded classes. That requires the Instrumentation reference and the only place where a JVM ever hands out such reference, are the initialization methods of Java Agents. So to use it, a Java Agent is unavoidable, even if it may be just a stub storing the reference, for use by your application code.
Note that starting with Java 9, there is the Launcher-Agent-Class manifest attribute for jar files that can specify the class of a Java Agent to start before the class specified with the Main-Class is launched. That way, you can easily have your Agent collaborating with your application code in your JVM, without the need for any additional command line options. The Agent can be as simple as having an agentmain method in your main class storing the Instrumentation reference in a static variable.
See the java.lang.instrument package documentation…
Getting hands on an Instrumentation instance when the JVM has not been started with Agents is trickier. It must support launching Agents after startup in general, e.g. via the Attach API. This answer demonstrates at its end such a self-attach to get hands on the Instrumentation. When you have the necessary manifest attribute in your application jar file, you could even use that as agent jar and omit the creation of a temporary stub file.
However, recent JVMs forbid self-attaching unless -Djdk.attach.allowAttachSelf=true has been specified at startup, but I suppose, taking additional steps at startup time, is precisely what you don’t want to do. One way to circumvent this, is to use another process. All this process has to to, is to attach to your original process and tell the JVM to start the Agent. Then, it may already terminate and everything else works the same way as before the introduction of this restriction.
As mentioned in this comment, Byte-Buddy has already implemented those necessary steps and the stripped-down Byte-Buddy-Agent contains that logic only, so you can use it to build your own logic atop it.
If I have:
build.gradle
System.out.println("${tasks.bootJar.mainClassName}")
Main class name has not been configured and it could not be resolved
So I comment out System.out.println, run the build again. Success.
Now if I uncomment out my System.out.println the main class name properly prints until I do a gradle clean.
Clearly some predicate job is running and being cached and that result is necessary for the println to work. Can anyone tell me how I can figure out which task it is and how to force it first?
I still don't understand how to properly troubleshoot this (ie a good reference on debugging task ordering and such). In my particular instance, browsing around on Github I found a more specific property which seems to always be available for mainClassName
tasks.bootJar.properties.mainClassName
I'm new to Liberty and am trying out the Batch (352) functionality. I can't find this as having been asked, either through search engines or stackoverflow, so I'm apparently missing something blatantly obvious...
I've created a simple test application in Liberty 8.5.5.9. It has the structure:
testbatchEAR
testbatchWAR
testbatchBatch
The EAR has been added to the server through the usual Add/Remove menu pick.
I'm now trying to submit the job from the command line using:
batchManager submit --batchManager=localhost:9443 --user=<> --password=<> --trustSslCertificates --jobXMLName=TestProcessor.xml --applicationName=testbatch
And I get back a message (truncated):
Error: Server returned HTTP response code: 500 for URL: https://localhost:9443/ibm/api/batch/jobinstances: [Error 500: com.ibm.ws.jbatch.rest.bridge.BatchContainerAppNotFoundException: Failed to load the application context for application testbatch#testbatch.war. Verify the application is installed.
I've tried testbatch, testbatchEAR, testbatchWAR, but from the "testbatch#testbatch.war" part of the message, it looks like it just uses the same name for both EAR and WAR, which I don't think is possible, is it?
What part of this am I missing? It must be right in front of my face, but every example or solution I find is using a naked WAR, which I can't do. Is there anywhere in liberty where I can find the application name? Should I be defining the names somewhere (server.xml?)?
Thanks in advance!
* Edit: Additional Information *
If I run it from the Eclipse Run Configurations > Java EE Batch Job section, it does run it, and doing a batchManager listJobs shows the application name as testbatchEAR#testbatchWAR.war.
So I guess the real question I have, is how can I put this name into the --applicationName option of batchManager.bat? It takes and makes #.war out of it. I've tried putting the full name from listJobs, but it won't allow a '#' character...
Specify both --applicationName and --moduleName in an EAR application
(As you discovered), in a case in which the batch application is packaged within a WAR within an EAR you will typically have to specify both --applicationName and --moduleName, e.g.:
batchManager submit --batchManager=localhost:9443 ... --applicationName=testbatch --moduleName=testbatchWAR.war ...
Specify just --applicationName in a WAR application
You may have seen examples though in which only the --applicationName is needed, e.g. here.
This syntax works in the case that the batch application is packaged as a WAR (but not a WAR within an EAR).
The "utility project" name here is not relevant, and there is no EJB so there is no --componentName relevant either.
The doc does mention this here in the section:
POST /ibm/api/batch/jobinstances
...
The applicationName identifies the batch application. It is required unless moduleName is specified, in which case the applicationName is derived from the moduleName by trimming off the .war or .jar suffix of the moduleName. For example, if you provide no applicationName and moduleName=SimpleBatchJob.war, then applicationName defaults to SimpleBatchJob.
The moduleName identifies the module within the batch application that contains the job artifacts, such as the JSL. The job is submitted under the module's component context. The moduleName is required unless applicationName is specified, in which case the moduleName is derived from the applicationName by appending .war to the applicationName. For example, if you provide applicationName=SimpleBatchJob and no moduleName, then moduleName defaults to SimpleBatchJob.war.
But if you're creating both a Web project and an EAR project in a tool like WDT, you're not going to easily be able to give the projects the same names (since they'll collide), so this really only works well in the case that there's not a separate EAR project. When the EAR project exists, you need both parameters.
As part of writing a Gradle plugin for Flyway, we stumbled upon a problem when dealing with Java migrations.
What is the best way to provide a Gradle plugin access on its classpath to the compiled classes of the project so that it can load and execute them?
So the situation is that we have a plugin that adds a task that wants to execute code contained in the project that the plugin is applied to. In this case, the task (class) should have an input property of type Iterable<File> that gets configured (by the plugin) with the class path of the code to be executed (e.g. sourceSets.main.runtimeClasspath). The task can then choose between the following ways to execute the code:
The task uses project.javaexec {} to execute the code in a separate JVM. If the code isn't directly executable, the task may need to inject some bootstrap code onto the javaexec class path. A potential alternative to using project.javaexec is to use a JavaExec task in the first place.
The task creates a new class loader, populates it with the class path, loads and instantiates the classes that serve as the entry point(s) to the API, and makes use of them as appropriate. If the task is written in Groovy, it can leverage duck typing, and no reflective code will be necessary beyond creating the entry points.
I'm having a stupid configuration issue with Ibatis in my Spring project. Please don't jump on me about how all this was setup, I'm just following the "in house project structure policy".
So here is the structure, we have the "src/main/resources/META-INF/" folder that contains all of our config files used by the application, and then there is a "src/test/resources/META-INF/" that contains only the config files that have different settings to run unit testing.
Well in our case that's only one file, the src/main/resources/META-INF/spring/application-config.xml became the src/test/resources/META-INF/spring/test-application-config.xml. I'm am not going to outline the small differences between the two, because that part works fine.
The test-application-config.xml imports the src/main/resources/META-INF/spring/data-access-config.xml file just fine, which in turns use the src/main/resources/META-INF/ibatis/sqlmap-config.xml successfully... After that is when it goes to Hell.
See up until now we're using Spring to find the next config files in the classpath, but when we hit sqlmap-config.xml we leave the spring framework for the ibatis framework I believe, which loads the resource files defined inside it relative to the classpath (that's taken from the doc, whatever that means).
Inside the sqlmap-config.xml are defined a few resource files we're using that live inside the src/main/resources/META-INF/ibatis/mapping folder.
They are referenced like this:
<sqlMapConfig><sqlMap resource="/META-INF/ibatis/mapping/MyObject.xml"/></sqlMapConfig>
That works fine when I run the app normally, but when I run my JUnit test cases I get an IO exception stating that it can't find the file /META-INF/ibatis/mapping/MyObject.xml.
I've tried to change the path in the sqlmap-config.xml to "mapping/MyObject.xml" but that didn't help. I've also tried to use the Spring classpath prefix "classpath:META-INF/ibatis/mapping/MyObject.xml", didn't work either.
Anyone would have any idea on how to set that Ibatis properly so it works for both the app and the junit?
Thanks.
To solve this problem, I removed all the the Ibatis files and folders from the src/test/resources/META-INF folder.
The sqlmap-config.xml in src/main/resources/META-INF/ibatis/mapping file now maps like this:
<sqlMapConfig><sqlMap resource="META-INF/ibatis/mapping/MyObject.xml"/></sqlMapConfig>
Please note that compared to my initial post the leading "/" is gone... I think that's what made the difference here.
Hopes this helps anyone running into similar issues.
Just to see whether what you are saying is actually the problem.. you might want to place your mappings (MyObject.xml) in the same folder as sqlmap-config.xml. I say this because I've had my fair share of spring + ibatis + unit testing problems. (see resolved question asked by me)
Also, you might be getting IO exception because the mappings file does not exist outside the container (when you run tests).
You should also post definition for bean created from SqlMapClientFactoryBean. This should have configLocation property that contains path to sqlMapConfig xml
I had the same problem and could not find a (quick) solution that explained what exactly could be going wrong. Hence my answer.
As Spring documentation for Ibatis says:
Remember that iBATIS loads resources from the class path, so be sure
to add the 'Account.xml' file to the class path.
In your case by adding META-INF to your webproject build path i.e. if you used Eclipse, set <classpathentry kind="src" path="META-INF"/> in your projects' .classpath (This will be visible under Navigator view in Eclipse)