Java files are not getting compiled - java

When the source files are part of a package and the directory structure of the source tree is not following the package hierarchy, javac ant task is unable to compile the java classes. However I see that on different machines, the same
build.xml
file runs fine.
For example if I have a java file with the package as com.abc.myapp.server.base and if my source file is placed under C:\mySource\base folder, javac is unable to compile this class.
However if I move my .java source file under C:\mySource\com\abc\myapp\server\base folder, everything goes fine.
I am using ANT 1.8.0 version and JDK 1.7.0_17 version on Windows 7.
Please advise

It sounds like you're not setting up your directory structure to match the packages of your java source files. The source for the class "org.example.abc.HelloWorld" should live in a directory like /src/org/example/abc.
Typically, you'd want your build.xml to be at the top-level of whatever project you're trying to build, and then the javac task inside it can reference the source directory where your package structure starts.
Something like this:
<project name="example" default="compile">
<target name="compile" description="compiles">
<mkdir dir="build"/>
<javac srcdir="src" destdir="build"/>
</target>
</project>
This is obviously very over simplified, but should help get you started.
If you're still having trouble, post your build.xml and some description of your project's layout so we can help.

Related

Eclipse ant task use custom WIX config file (wxs) file instead default wxs file

I am using Eclipse 4.5.2 to deploy JavaFX application (JDK 1.8). I want to change an IniFile during the installation. Ant task or JavaFX deploy is generating a wxi and wxs file in temp folder AppData\Local\Temp\fxbundler5060494280971686435\windows
But I want that Ant is using my custom wxs file. How Do I do that?
I did not find a clear description where to place my custom wxs file. I placed it under my project \build\Package\Windows\test.wxs.
But output is stating:
Config files are saved to C:\Users\xxx\AppData\Local\Temp\fxbundler5060494280971686435\windows. Use them to customize package.
Using default package resource [WiX config file] (add package/windows/test.wxs to the class path to customize)
My folder structure looks like this:
project
src
ressources
build
build
classes
libs
src
package
windows
test.wxs
build.xml
What do I have to do, that my custom wxs file is used???
Thanks in advance.
I got the same problem . while,I used inno setup to build setup.exe file .
My solution is writing my own inno setup script based on javafx script which found in C:\Users\xxx\AppData\Local\Temp\fxbundler5dss886329843971686435\windows, then writing an another ant task depends on fx:deploy task that I execute the innosetup script in command line like blow:
<target name="do-mydeplopy" depends="do-fxdeploy, prepare-deploy">
<exec executable="iscc">
<arg value="my-deploy.iss"/>
</exec>
</target>
You should learn how to write the setup script.

Built java project in Netbeans doesn’t include external TEXT files

Sorry if the question is basic. I’m trying to build a java project that include text files :
File file = new File("data/include/foo.txt");
Problem is that with Netbeans, Built and Clean actions are done without taking into account external text files.
Can you please help me solving this problem.
In Netbeans there are basically two types of java projects. One is using ANT as its build machine and one is using maven.
Using ANT to build:
You have to modify or build a build.xml. Netbeans offers some targets in its standard build.xml to trigger events on each part of the build process.
So to include some additional resource files (in your case some text files) you should add your build.xml with a target like
<target name="-post-jar">
<jar destfile="dist/myjar.jar" update="true">
<fileset dir="${basedir}">
<include name="data/include/*"/>
</fileset>
</jar>
</target>
It means that after your JAR is build the files from ${basedir}/files/* are included as well.
Using MAVEN to build:
Netbeans uses here completely Mavens infrastructure. So Maven does have a standard mechanism to recognize resource files to include. It all comes down to place these files in a specific place of the project. Assuming you did not change this standard directory layout of maven JAR projects is is something like:
Project
src
main
java
resources
...
So all files placed in src/main/resources (including subfolders) are included in your JAR automatically.
Read more here
Edit 1:
To access this resource files you cannot use File objects. This is done using the class own getResource methods:
App.class.getResourceAsStream("data.xml")
App.class.getResource("data.xml")
Here my class is App and my datafile is data.xml which is in the same directory as my class. This is relative adressed. But if you use a path with a heading / then your path is JAR file absolute. Read more about this here.

Javah Command in Eclipse Ant Build Script

I'm following this tutorial about creating JNI files for Mac OS X. The tutorial is written for NetBeans, but I'm trying to follow it with Eclipse. Unfortunately, this has caused me to be stuck at step 4.1.3, which is about generating a .h file using ant:
Modify the build.xml file of your Netbeans project by adding the
following before the closing tag:
<target name="-post-compile">
<javah
destdir="./build"
force="yes"
class="ca.weblite.jniexample.NSSavePanel"
classpath="./build/classes"
/> </target>
First off, it seems that Eclipse projects don't include a build.xml file by default, so I used these instructions to generate one. Then I added the command as shown above. But when I build with the ant script, the .h file does not get built. No error message related to this is generated.
I believe that the reason is because Eclipse projects do not have a "./build" folder as shown in the examples, but I don't know what to put in its place. Could anybody please let me know how to fix this issue?
First, let's assume your Eclipse project folder structure is like this:
src/ (source files)
bin/ (compiled class files)
The above folders should be configured in your Java Build Path (see Project > Properties). The below folder and file you will need to create yourself (just right-click > New...).
build/ (build products)
build.xml (build script)
Inside each of bin and src folders, you should have a sub-directory structure like:
ca
|--weblite
|--jniexample
There should be a source file at src/ca/weblite/jniexample/NSSavePanel.java. And there should be a compiled class file at bin/ca/weblite/jniexample/NSSavePanel.class.
Your build.xml file should look like this:
<project name="Build" default="-post-compile">
<target name="-post-compile">
<javah destdir="./build" force="yes" class="ca.weblite.jniexample.NSSavePanel" classpath="./bin" />
</target>
</project>
After executing your build script, you should see a file at build/ca_weblite_jniexampe_NSSavePanel.h.

Eclipse: Exporting JAR when compiling a dependent application

I am working on an SDK, exported as a JAR, that will be used by an Android App. I have created a test App to teste the behavior of the SDK. I am looking for an easy way to export the JAR into the test App's library folder when test App is compiled. So all the changes made in JAR can be tested along with the changes in the test App.
So current work flow is:
Make changes in SDK -> Compile -> Export JAR -> Place JAR in test App's Lib folder -> compile test App -> Run test
Is there a way to link it all together, so when the test App is complied, all the previos steps will run automatically?
Create one ant file to compile the jar and copy it to the "app lib folder", also configure it to run when you build the project.
Here is an example of an ant file to generate the jar
<?xml version="1.0"?>
<project name="your-project-name" default="jar" basedir="..">
<property name="app.lib.dir" value="C:/folder_destination_of_the_jar"/>
<property name="jar.filename" value="jar-filename.jar"/>
<property name="core.build.dir" value="bin"/>
<target name="jar">
<jar jarfile="${app.lib.dir}/${jar.filename}">
<fileset dir="${core.build.dir}"/>
</jar>
</target>
</project>
If you are using eclipse as your IDE, follow the steps below to configure it to run when you build the project:
right click your project->Properties->Builders->New->Choose Ant Builder->Add the ant file as Buildfile

Java: Add libraries and txt preference files to project

I'm using NetBeans to import a series of libraries from my Arduino IDE. I'm following directions from the following link:
http://silveiraneto.net/2009/03/01/arduino-and-java/
This works provided I use the Arduino-0013 version of the IDE install, more current versions do not compile using this method.
I have found that using the Arudino-0013 set as the working directory is NOT necessary if I manually move the "preferences.txt" and "keywords.txt" and "librxtxSerial.so" files into the lib folder in my Java dist (build) folder, and also move the entire Arduino-0013 "Hardware" folder also into my Java dist (build) folder.
When I do this I can run the Java program from the dist directory on the command line. Using the command:
java -jar myProgram.jar
rather than having to go into the Arudino-0013 as my working directory and use -cp to get my program to work (which I haven't worked out how to do incidentally):
Is there a way to include these .txt files and the Arudino hardware folder with all the files it contains when I build the project with NetBeans? The reason I ask is because it's getting annoying having to do this manually every time I do a new build.
My answer is not specific to netbeans but you can try:
Make an Apache ANT build file to build your project. In that file make a copy task which will copy txt files in your build. By doing this you will not have to so it manually. See here: http://wiki.netbeans.org/NetbeansedAnt to know how to work with ANT in NetBeans.
In Netbeans, if you switch from the Projects tab to the Files tab, you'll see that you have a build.xml file. This is an Ant build.xml file. You can configure Ant to automatically copy the files for you whenever your build your project. You would essentially have something like this:
<project ...>
<target name="-pre-compile">
<copy file="some/path/preferences.txt" todir="../some/dir"/>
<copy file="some/path/keywords.txt" todir="../some/dir"/>
<copy file="some/path/librxtxSerial.so" todir="../some/dir"/>
</target>
<target name="-post-compile">
<copy todir="build/dir">
<fileset dir="some/path/Arduino-0013"/>
</copy>
</target>
</project>
There is more information in the build.xml file about what you can and can't hook into. The Ant documentation is good, and the Tasks section of the Ant Manual will be particularly useful.
There should be a dependencies section in NetBeans for your project. You can then add external libraries to your project, such as local JAR files you've got. The best way would probably be to jar up the text files and Arduino directory together, then add that JAR file as a compile-time (and/or run-time) dependency to your project. Now, when you compile your project in NetBeans it should include the specified JAR file on the classpath and voila.
Sorry to not give you more NetBeans-specific direction, I've only used the IDE a couple of times, but all IDEs will allow you to add local JAR files and third-party libraries as dependencies to your project, you just need to find where in the IDE you can do that.
Another idea that might work is to set NetBeans to use your local copy of Java for compilation instead of the one that came bundled with the IDE, that way you don't need to fuss with project dependencies. Again, I don't know where in NetBeans to set this, but start in the General Settings (or perhaps the Project-specific Settings) and find the Java/compilation section; hopefully there's an option to specify which JDK to use, then point it at your local copy.

Categories

Resources