How to open this program? - java

I need open this application-->
Decision tree
I have used netbeans and it has not worked, so I have installed eclipse and it seems that the file recognizes me.
What I do is import that application from Github, until there everything perfect, the problem is that when I give it to run, it does not work.
One problem I get is the following:
Buildfile: C:\Users\user1\workspace\Arbolito\java-decision-tree-master\build.xml
compile:
[javac] Compiling 9 source files to C:\Users\user1\workspace\Arbolito\java-decision-tree-master\build\classes
BUILD FAILED
C:\Users\user1\workspace\Arbolito\java-decision-tree-master\build.xml:19:
C:\Users\user1\workspace\Arbolito\java-decision-tree-master\lib
does not exist.
Total time: 550 milliseconds
I put the line of code in the XML file that gives me the problem
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false" debug="on" />
</target>
Does anyone know how to run the program?

Create a lib folder in your project and include SL4J and Junit jar in that folder.

Related

Building with Ant in Eclipse - javac not recognizing lambda expression (Java 1.8)

I am trying to build an existing project using Ant in Eclipse. The problem is that javac does not recognize the use of a Lambda expression (error: illegal start of expression) in one of the files, and the build fails during the compile phase of the Ant.
Within Eclipse, I've ensured that the Java Compiler compliance level is set to 1.8 and that Java 8 is in the Java Build Path.
I've also ensured that the my Path, JAVA_HOME, and JRE_HOME all point to my Java 8 directory (in Path it points to the /bin directory).
For giggles, the compile section of my build.xml file is:
<target name="compile" depends="setup">
<javac destdir="${base}/${build.dir}"
srcdir="${base}/${src.dir}"
deprecation="true"
verbose="false"
includeantruntime="false">
<classpath refid="libs" />
</javac>
</target>
I'm not really sure what to do next. I've resorted to restarting Eclipse hoping for magic to happen. Any suggestions or help are welcome! Thanks in advance.
Adding <echo> Java version: ${ant.java.version}</echo> to my build.xml revealed that Ant was still running Java 1.7.
I added the directory location of my Java 8 javac and modified the javac task with the executable and fork attributes to use it:
<property name="javac1.8" location="/path/to/java8/bin/javac" />
<target name="compile" depends="setup">
<javac executable="{$javac1.8}" fork="yes"
destdir="${base}/${build.dir}"
srcdir="${base}/${src.dir}"
deprecation="true"
verbose="false"
includeantruntime="false">
<classpath refid="libs" />
</javac>
</target>
Thanks so much for the comments #Jim Garrison, #wero, and #greg-449. Your powers combined lead me to my answer.

How to make build.xml file to run a program?

Two questions.
How do I make a build.xml file run a Java program? What are the commands?
Is there a way to run a Java program through Ant , without creating the .class files?
1- You can use a java command to run java program and create a custom task like:
<target name="run">
<java jar="build/jar/HelloWorld.jar" fork="true"/>
</target>
2- I think no, you need to comile your code before execute it, and it's not a big problem, if you use ANT. Just make a task to do that like:
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>
And then you can execute a main method of custom java class, like:
<java classname="com.example.MainClass" depends="compile">
<classpath>
<pathelement path="build/classes"/>
</classpath>
</java>
Look here for a basic tutorial on Ant: https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
As far as I know, it is impossible to run a Java program without creating .class files, as the JVM interprets .class files rather than .java files.
I think you have misunderstood the purpose of Ant. It builds Java applications, and part of this build involves compiling the .java files into .class files for you. Typically this would be so that you can deploy applications onto a server more easily.
To compile .java files using Ant, use the javac command, as in the tutorial:
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>

Classpath, Compile, and Run with Ant?

I'm completely new to Ant and need to add a couple jars to my classpath, compile a couple .java files, and run a junit test, all in Ant. I've been looking at a few online tutorials and manuals, but can't seem to wrap my head around the entire xml writing process.
All the previously-written code resides in a single directory called XXX.
In XXX there are two jars I need to add to my classpath with export CLASSPATH=$CLASSPATH:jar1:jar2, two java files I compile with javac *.java, one of which contains several junit tests that I run with java org.junit.runner.JUnitCore Tests. The build.xml would reside in XXX as well (I believe).
So far I have the following for just compiling, although I think there's a lot missing.
<?xml version="1.0"?>
<project name="EtlAutomation" default="compile" basedir=".">
<property name="src" value="${basedir}"/>
<target name="compile">
<!-- Compile .java files -->
<javac srcdir="${src}" destdir="${src}"/>
</target>
</project>
What else do I need to add to compile *.java in the current directory? How can I run the export CLASSPATH command, and finally the junit commend?
I'm not asking for anyone to write my code, but it would be appreciated. If anyone knows a good beginner tutorial for a unix environment, that would be awesome. I'm a total beginner with ant so I'll take what I can get.
Here is a previous question addressing this. And this may work for you:
<project name="EtlAutomation" default="compile" basedir=".">
<property name="src" value="${basedir}"/>
<path id="compile.classpath">
<fileset dir="./">
<include name="*.jar"/>
</fileset>
</path>
<target name="compile" >
<javac destdir="${src}" srcdir="${src}">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="run" depends="compile">
<junit>
<classpath refid="compile.classpath" />
<test name="TestExample" />
</junit>
</target>
</project>

Custom BuildFile for a Netbeans Java projects fails

I have a Netbeans project that has a source folder (outside the Netbeans project folder). Now, When I compile the source code from the IDE, everything works fine. But, when I use my own build script it gives an error at runtime.
The application depends on several external libraries that I specify using the path element and the corresponding refid attribute in classpath tag (see code below)
Here is my buildfile
<project name="XX" default="dist" basedir=".">
<property name="dir.src" location="E:/XX git/xx/src"/>
<property name="nbproj" location="E:/Netbeans Project"/>
<property name="dir.dist" value="dist"/>
<path id="libs">
<fileset dir="${nbproj}/dist/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="clean">
<delete dir="dist"/>
<delete dir="release"/>
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="${dir.src}" destdir="build/classes" includeantruntime="false">
<classpath refid="libs"/>
</javac>
</target>
</project>
When I compile it using ant compile, it compiles all the source files without any error. But, when I execute it using the command
java -cp "E:\Netbeans Project\dist\lib\*;." controller.CZSaw
it creates the application GUI nicely and then when I perform some action, it fails with the following error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at controller.viewsynchronizer.CZViewManager.getIcon(Unknown Source)
at view.script.CZScriptView.<init>(Unknown Source)
at controller.script.CZScriptProcessor.<init>(Unknown Source)
at controller.script.CZScriptProcessor.getInstance(Unknown Source)
...
I know it would be difficult to point out some error looking just at the source code. But, as the same code compiled and worked nicely from the IDE, I think there is something wrong with the way I am compiling. Is there any apparent mistake in the buildfile.
Let me know if I missed some useful information here.
Classic mistake: assuming that because "everything worked fine" in one setting means that you've done everything right and are blameless for anything that subsequently goes wrong.
It means that your IDE took care of some things that you're ignorant of.
Look at the first class that's yours:
controller.viewsynchronizer.CZViewManager.getIcon(Unknown Source)
It looks like your controller is looking for an icon image that's not in the CLASSPATH.

Maven Ant Task tries to open pom as zip and fails

I am trying to run an Maven Ant Task with plugin version 2.1.3 and for some reason running into this error:
[javac] Compiling 101 source files to /home/raido/Workspace2/foobar/classes
[javac] error: error reading /home/raido/.m2/repository/foobar/1.0/foobar-1.0.pom; error in opening zip file
[javac] 1 error
Why is it trying to read a xml file as an zip file and how can I avoid this? The file itself is perfectly fine and readable.
That part from the build.xml file:
<target name="compile" depends="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<javac classpathref="compile.dependency.path" debug="on"
encoding="UTF-8"
deprecation="on" destdir="${classes.dir}"
includes="bar/**/*.java" optimize="off"
srcdir="${src.dir}" />
</target>
The error is targeted to the closing sign > on the srcdir row i.e. the whole tag.
It might be corrupt zip. you can remove the foobar/1.0/ dir from your maven repos and let maven download new fresh version
Show us your definition of compile.dependency.path. Seems like the pattern there is not quite correct and allows .pom files (if it's **/**, for example), which will clearly not work.
I finally figured it out. The problem was that the main ant file had a specific task that produced JAR-s of the modules but I hadn't done it. This shows how important documentation sometimes is which this project doesn't have at all!

Categories

Resources