I am new to optaplanner
i worked in iDE and created a working prototype and now want to run in a prod mimic testing.
i created a jar of my entire project
but when i invoke the jar with the input files,
i get exception as "Null POinter Exception"
I tried created SolverFactory by two ways
Trial 1:
SolverFactory<PocSolution> factory = SolverFactory.createFromXmlResource(SOLVER_CONFIG,this.getClass().getClassLoader());
Trial 2:
SolverFactory<PocSolution> factory = SolverFactory.createFromXmlReader(new FileReader(SOLVER_CONFIG),this.getClass().getClassLoader());
Exception in thread "main" java.lang.NullPointerException
at org.kie.internal.io.ResourceFactory.newByteArrayResource(ResourceFactory.java:66)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.getResource(AbstractKieModule.java:299)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:264)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:259)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:228)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:74)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:251)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:219)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:177)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:503)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:331)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:220)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:57)
at org.optaplanner.examples.MyPoc.app.Poc.solve(Poc.java:132)
at org.optaplanner.examples.MyPoc.app.Poc.main(Poc.java:41)
Your solver config file is being read successfully. The problem seems to be inside the <scoreDirectorFactory> element, where you specify score DRL. Please make sure that you use the <scoreDrl> element and not <scoreDrlFile>. <scoreDrlFile> is supposed to contain a local file system path whereas <scoreDrl> is used to load a classpath resource (which is the case when the DRL file is located inside a JAR). It should look similar to:
<scoreDirectorFactory>
<scoreDrl>org/myproj/core/solver/myRules.drl</scoreDrl>
</scoreDirectorFactory>
Related
I'm having what seems to be a classloader/jar issue. Websphere 7, JDK 6.
Talking to a webservice works fine when the code is running in a simple, standalone Java class.
((WSBindingProvider) docManClient).setOutboundHeaders(Headers.create(otAuthElement));
In the debugger, the docManClient object has this toString():
JAX-WS RI 2.1.4-b01-: Stub for http://innov15.ncr.pwgsc.gc.ca/innov15_cws/DocumentManagement.svc
The class path includes jaxws-rt-2.1.4.jar.
When the code is running inside Websphere, the cast fails.
((WSBindingProvider) docManClient).setOutboundHeaders(Headers.create(otAuthElement));
java.lang.ClassCastException: com.sun.proxy.$Proxy484 incompatible with com.sun.xml.ws.developer.WSBindingProvider
In the debugger, the docManClient object has this toString():
org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler#a460a46
This jar is in Websphere-land only, and is not part of my project's .ear file:
C:\dev_tools\server\IBM\WebSphere\AppServer\plugins\org.apache.axis2.jar
I attempted to change the app config, to prefer its own classes above those of Websphere.
I used the wsadim tool to change to PARENT_LAST, but this had no affect on the observed behaviour:
set dep [$AdminConfig getid /Deployment:my-ear/]
set depObject [$AdminConfig showAttribute $dep deployedObject]
set classldr [$AdminConfig showAttribute $depObject classloader]
$AdminConfig showall $classldr
$AdminConfig modify $classldr {{mode PARENT_LAST}}
$AdminConfig save
$AdminConfig showall $classldr
The app is an .ear which contains a single .war.
EDIT added later: I'm not clear on the relation between jax-ws-rt.jar and axis2.jar. The axis2.jar is not a drop-in replacement for jax-ws-rt.jar: when I switch to axis2.jar, the code no longer compiles.
I want to load dynamically XML meta-data files that are not in the classpath (the XML meta-data files will be generated after launching my app).
I thought I could call the method
MetaDataManager.registerFile(java.lang.String fileURLString, FileMetaData filemd, ClassLoaderResolver clr)
Then, I tried the API enhancement, so I added the following lines:
JDOEnhancer enhancer = JDOHelper.getEnhancer();
enhancer.setVerbose(true);
enhancer.addClasses(ClassToPersist.class.getName()).enhance();
getClass().getClassLoader().loadClass(ClassToPersist.class.getName());
The following jars are in the classpath: datanucleus-api-jdo.jar, datanucleus-connectionpool.jar, datanucleus-core.jar datanucleus-rdbms.jar, jdo-api.jar, asm.jar.
But when I launch my app, I get this exception:
Caused by: mypackage.MyException:
org.datanucleus.api.jdo.exceptions.ClassNotPersistenceCapableException: The class "mypackage.ClassToPersist" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
Do you please have any idea how to fix this ?
PS: I also noticed that the method enhance returns 0 which indicates that the class has not been enhanced (we could exclude the other options)
Thanks
I think I found an easy way to fix this.
At runtime, I created a jar that contains the updated metadata file as META-INF/package.jdo. Then I added this jar to the classpath as described here
Using this hacks, I didn't need to re-enhace my class since it is enhanced after compilation.
(But for information, I had to call JDOEnhancer.addFiles() to enhance my class.)
So your call to loadClass has loaded the unenhanced class (since it would have been loaded in order to perform the enhancement presumably), and you didn't follow the tutorial that is provided at http://www.datanucleus.org/documentation/development/dynamic_class_metadata_enhance_runtime.html
I'm running into problems when I turn my (working) java into an executable jar file.
I have a very simple number sorting program written. It's spread across two files (TreeGui.java and SortTree.java) that each do more or less what they say. TreeGui has an input textarea, a button and an output area. Pressing the button passes the input text to SortTree, which returns nicely sorted numbers that appear in the output box.
When I compile each file, and then run TreeGui, everything works fine
javac TreeGui.java
javac SortTree.java
java TreeGui
...runs everything lovely.
Now, when I try and put those classes into a jar file I keep bumping into the same string of problems. I have a manifest (TreeGuiManifest.txt) with the following (and a blank new line):
Main-Class: TreeGui
but when I put the whole lot together:
jar cmf TreeGuiManifest.txt TreeGui.jar TreeGui.class SortTree.class
I hit problems. Whether I run it directly by selecting the jar file or by using "java -jar TreeGui.jar" in the console, the program will load fine but the moment the button is pressed it throws a whole string that start like this and carry on for a long way:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: SortTree TreeNode
at SortTree.treeInsert(SortTree.java:35)
at SortTree.main(SortTree.java:24)
at TreeGui.actionPerformed(TreeGui.java:66)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
etc. etc.
It's clearly struggling to find elements in the SortTree code that pressing the button in TreeGui demands but I'm not sure what I can do to make it work.
Am I missing something really obvious? I'm using a variety of imported java.utils.*; etc, do I have to mention them when I make my jar file? Thanks for any help.
(The only reason I haven't pasted the actual code of the programmes here is that it all works perfectly when it's not a Jar file... I'll happily add them if necessary though)
I've been trying to figure out how to programmatically add files to an Xcode4 project and it seemed like AppleScript would be the way to go, however I'm running into "missing value" errors.
Here's the code I've got:
tell application "Xcode"
set theProject to first project
set theTarget to first target of theProject
set theBuildPhase to compile sources phase of theTarget
tell first group of theProject
set theFileRef to make new file reference with properties {full path:"/Users/jeff/Projects/XcodeTest/XcodeTest/MyViewController.h", name:"MyViewController.h", path:"XcodeTest/MyViewController.h", path type:group relative}
add theFileRef to theProject
end tell
--tell theBuildPhase to make new build file with properties {build phase:theBuildPhase, name:"MyViewController.h", file reference:theFileRef, target:theTarget, project:theProject}
end tell
I've tried the commented-out line instead of the add-command as well, but that doesn't work either (I get "missing value").
The 'add' error is:
error "Xcode got an error: file reference id \"251AD3431432472E006E300F\" of Xcode 3 group id \"251AD32C14324645006E300F\" of project \"XcodeTest\" of workspace document \"XcodeTest.xcodeproj/project.xcworkspace\" doesn’t understand the add message." number -1708 from file reference id "251AD3431432472E006E300F" of Xcode 3 group id "251AD32C14324645006E300F" of project "XcodeTest" of workspace document "XcodeTest.xcodeproj/project.xcworkspace"
The "make new reference" does add the file to the list of files in Xcode, but I also need it to be added to the project target so that I can add actions and outlets to the file from Xcode w/o having to first check the checkbox to add it to the "target membership".
I ended up sending this question to the devs on the xcode developer list and the response I got was effectively "you can't".
This appears to be completely broken in Xcode4, but I've seen a project that does it. I think what they are doing is parsing and modifying the "project.pbxproj" file directly. (this file is hidden inside the xcodeproj bundle)
The file is a GUID soup, but once you look at it for a while it seems possible to safely modify it, especially if you are only adding stuff.
Edit:
Found this stackoverflow answer that might help.
Tutorial or Guide for Scripting XCode Build Phases
There is a poorly documented user defined build setting that can be added. Files can be both excluded and included from compilation
Go to your target's Build Settings > Tap the + button > Add User-Defined Setting
The key is either INCLUDED_SOURCE_FILE_NAMES or EXCLUDED_SOURCE_FILE_NAMES
The value is a space separated list of file paths
See reference:
http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html
I received a Flex project and when trying to compile it i get a few 1046 errors that say the Type was not found or was not a compile-time constant MyClass
however - the respective files are listed on the top of the file in an import clause like this:
import com.folder1.folder2.folder3.MyClass;
and if i check the folder structure, MyClass.as is there.
however, if i type this same line (import com.folder1.folder2.folder3.MyClass;) and check at each . what the autocompletion suggests, I see only a subset of the as classes that are actually there on the harddisk.
What determines which classes and folders are suggested by the autocompletion function? I don't get any compile error on the corresponding import statements that import MyClass
//edit:
screenshot 1 shows the file in which the error occurs that tries to import the class in question (Updater)
http://neo.cycovery.com/flex_problem.gif
screenshot 2 shows the file Updater.as
http://neo.cycovery.com/flex_problem2.gif
the censored part of the path matches in both cases (folder structure and package statement in Updater.as)
screenshot 3 shows where the error actually happens:
http://neo.cycovery.com/flex_problem3.gif
interestingly, the variable declaration
private var _updater:Updater = new Updater();
further up in the file does not give an error
This project is set up wrong. Its obvious your application can not find the classes.
Move your "com" folder and all of the contents into your "src" folder.
Or perhaps include the files in your source path?
right click on the project name->properties->flex Build Path->add folder
the import is based on the 'package' declaration within the file itself (at the top of the file). If the file's package declaration does not match the actual folder structure, you will get problems.
Check the classes you can't see in the autocompletion list. Maybe those classes' package name doesn't match the actual structure.
Rob
Check your actionscript source paths. Any chance that the folders you are seeing (events and objects) are in there explicitly, and the others are not? Normally, you have all your source inside a folder like src that is in the source path, so that the compiler can find anything anywhere inside it. But you can just as easily make your source paths too specific and just see a few things...