Problems turning working programs into executable Jars - jar

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)

Related

How to view decompiled R code in order to debug it?

I'm working with ASSIGN SESSION:DEBUG-ALERT = TRUE. and as a result, while testing a program I get an error message with following callstack details (only the first line):
--> USER-INTERFACE-TRIGGER my_own_window.w at line 587 (\\<official_build_server_directory>\my_own_window.r)
my_own_window.w at line 709 (\\<official_build_server>\<my_own_window.r)
...
As you can see, something's wrong with my window at lines 587 and 709, but:
While compiling the window files, some things happen which mess with the line numbers, and the mentioned line numbers are the ones from the compiled *.r files, which are different than the ones from the original *.w files.
In order to be sure about the line numbers, I would need a de-compiler, or at least a *.r-viewer (being based on an internal de-compiler).
It's not the r-code's you need to look into. It's the DEBUG-LISTING files. If you have the source-code execute:
COMPILE my_own_window.w DEBUG-LIST c:\temp\my-own_window.debuglist .
That file shows you the actual line numbers.
For future reference: so far Progress has not provided a decompiler. Any available decompilers at the time of writing this are 3rd party and also possibly not legal regarding Progress OpenEdge licenses.
You can also click on the 'Debug' button in that alert box, which will invoke the debugger which steps through an 'on the fly' debug-listing.
For the debug-listing on the fly to work, you will need to have the source files in your propath. The debugger will detect and complain if source files have changed after your code was executed.
And you will also need to ensure the debugger is enabled by starting proenv and then prodebugenable -enable-all

Optaplanner as jar does not seem to read xml file

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>

QAbstractItemModel testing using modeltest

I'm looking for a good tutorial on how to use modeltest to test models based on QAbstractItemModel. I don't know how to interpret debug messages that are displayed.
Also I'm having trouble configuring modeltest project to work with my app in QtCreator. Including the .pri/.pro doesn't work. I get an error saying "No rule to mage target ..". After fixing paths in modeltest/modeltest.pro file it starts to compile. But i get this wierd assertion
ASSERT: "QTest::testLogger" in file c:\ndk_buildrepos\qt-desktop\src\testlib\qtestlog.cpp, line 232
Any ideas why this happens ?
My modeltest folder is located inside my project. I added following line at the end of my *.pro file
include(modeltest/modeltest.pri)
The modeltest.pri file contains the following
load(qttest_p4)
SOURCES += modeltest/modeltest.cpp modeltest/dynamictreemodel.cpp
HEADERS += modeltest/modeltest.h modeltest/dynamictreemodel.h
I modified my code to use modeltest this way
model = new TasksModel(this);
new ModelTest(model, this);
ui->treeView->setModel(model);
TasksModel is my implementation of QAbstractItemModel model.
ui->treeView is the widget that displays data.
No other modifications where made while integrating modeltest with my app.
Qt version is 4.7.
This will sound a little overgeeky - but it is, in fact, what the ModelChecker dev intended for you to do ;) When you hit one of the asserts, go to the point in the code where it is hit and read the comments which are written along with it. The entire thing is extremely heavily commented, and describes what is breaking and likely reasons why. This is by far easiest to do if you run your app through a GUI debugger, such as that included in for example KDevelop, Qt Creator or Visual Studio.
The reason you are getting this error is because you aren't actually using the ModelTest inside a proper QTestLib test case. If you take a look at /tests/auto/modeltest (where you presumably got the modeltest class in the first place), you can see how to properly construct a test case using the ModelTest.

Flex/AIR: call JSFL

I've written a JSFL file to publish some fla's, and now I'd like to call that script from a flex / AIR application.
So the user should browse to the JSFL-file and select it. After selecting the JSFL-file should run and do whatever is described in the JSFL. If I run the JSFL, no problems occur and everything goes fine. However, I can't seem to call the file from my flex/AIR application.
I've tried writing a flash AS3.0 file and call the JSFL from there but that doesn't work either.
The function I use is MMExecute but still nothing ... Searched for it quite some time now and I'd really like to do this. Anyway, here's some code...
//ABOVE IS THE SELECT EVENT
jsflpath = evt.target.nativePath;
MMExecute('fl.runScript("'+filePath+'" );');
George is exactly right. With AIR 2.0+, you could use NativeApplication to launch the script file directly in Flash.
More on NativeApplication here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/NativeApplication.html
http://www.adobe.com/devnet/air/flex/quickstart/articles/interacting_with_native_process.html

Specflow error using TestDriven.Net - Couldn't Find Type

I'm trying out Specflow for the first time, and have created a VS2010 project with a reference to TechTalk.SpecFlow, as well as nunit.framework. I've added a sample Feature file:
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
#mytag
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
When I execuyte the test (using TestDriven.Net), I get the following error:
Test 'T:SpecFlowFeature1' failed: Couldn't find type with name 'SpecFlowFeature1'
System.Exception: Couldn't find type with name 'SpecFlowFeature1'
at MutantDesign.Xml.Documentation.MemberInfoUtilities.FindMemberInfo(Assembly assembly, String cref)
at TestDriven.TestRunner.AdaptorTestRunner.Run(ITestListener testListener, ITraceListener traceListener, String assemblyPath, String testPath)
at TestDriven.TestRunner.ThreadTestRunner.Runner.Run()
Anyone know what I'm missing?
Actually traced this down to how I was running the test. Right clicking the ".feature" file (or anywhere within that file) and selecting "Run Tests" resulted in the error. Right clicking the underlying ".feature.cs" file and selecting "Run Tests" executed correctly. Looks like TestDriven.Net wasn't able to "understand" the "*.feature" file.
I typically start "Couldn't find type..." errors in my references folder and make sure that the library that I'm referencing is being referenced correctly and that the version that's being referenced isn't outdated.
Also, make sure that your SpecFlowFeature1 class isn't mistakenly declared as private. Visual Studio creates new classes (by default) as private and if you don't specify a class as public, it will remain private and not "visible" to outside projects.

Resources