Sign in to follow this  

[java] Can't refer to another package properly.

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have two classes: ~/Code/Games/Java/RavMush/Mush/Server/MushAcceptSocket.java and ~/Code/Games/Java/RavMush/Mush/Foundation/Network/MushSocket.java In MushAcceptSocket I reference MushSocket with "import Mush.Foundation.Network.*;"... ant gives me back the error
[javac] /Users/mike/Code/Games/Java/RavMush/Mush/Server/MushAcceptSocket.java:7: package Mush.Foundation.Network does not exist

The ant build file is following:
<project name="RavMush" default="ClientServer">
        <target name="Foundation" description="The Foundation Classes" depends="">
                <!-- compile all java source in foundation -->
                <javac srcdir="Mush/Foundation/Network"/>
                <javac srcdir="Mush/Foundation"/>
        </target>

        <target name="Server" depends="Foundation" description="The minimal server">
                <!-- Compile all Java source in Server -->
                <javac srcdir="Mush/Server"/>
        </target>

        <target name="Client" depends="Foundation" description="The minimal client">
                <!-- Compile all Java source in Client -->
                <javac srcdir="Mush/Client"/>
        </target>

        <target name="ClientServer" depends="Client, Server" description="The server and client (default)"/>
</project>

And the top lines of both involved files are: MushSocket:
package Mush.Foundation.Network;

MushAcceptSocket:
package Mush.Server;

MushAcceptSocket just uses MushSocket, it is not derived from it. Have I screwed up my ant build file? I'm new to ant and complex Java package structure, but I don't want to move onto Eclipse because it's slow and painful on my computer.

Share this post


Link to post
Share on other sites

<project name="RavMush" default="ClientServer">
<target name="Foundation" description="The Foundation Classes" depends="">
<!-- compile all java source in foundation -->
<javac destdir="bin" debug="off" deprecation="off">
<src path="Code/Games/Java/RavMush" />
<include name="**/*.java" />
</javac>
</target>

<target name="Server" depends="Foundation" description="The minimal server">
<!-- Compile all Java source in Server -->
<javac destdir="bin" debug="off" deprecation="off">
<src path="Code/Games/Java/RavMush" />
<include name="Mush/Server/*.java" />
</javac>
</target>

<target name="Client" depends="Foundation" description="The minimal client">
<!-- Compile all Java source in Client -->
<javac destdir="bin" debug="off" deprecation="off">
<src path="Code/Games/Java/RavMush" />
<include name="Mush/Client/*.java" />
</javac>
</target>

<target name="ClientServer" depends="Client, Server" description="The server and client (default)"/>
</project>



Here is a sample ant build script that I use. It is a little complicated because it was made to squeeze the end file down as small as possible. But this might give you some ideas on how they work.

<project name="Asteroids4k" default="compile" basedir=".">
<taskdef resource="proguard/ant/task.properties" classpath="C:/Apps/Programming/Java/proguard3.5/lib/proguard.jar" />
<taskdef name="jarg" classname="jarg.JargTask" classpath="C:/Apps/Programming/Java/jarg/jarg.jar" />

<description>
Ant build script for Asteroids, Java 4K entry
</description>

<!-- Global properties for this script -->
<property environment="env" />
<property name="j4k.root" location="${basedir}" />
<property name="j4k.src" location="${j4k.root}/src" />
<property name="j4k.bin" location="${j4k.root}/bin" />
<property name="j4k.dist" location="${j4k.root}/dist" />

<target name="clean" description="deletes classes and archive directories">
<!-- Delete the output directory trees -->
<delete dir="${j4k.bin}" />
<delete dir="${j4k.dist}" />
</target>

<target name="init">
<echo>${ant.version}</echo>
<!-- Creates a time stamp -->
<tstamp>
<format property="timestamp" pattern="yyyyMMddHHmmss" />
</tstamp>
<!-- Create the classes directory structure -->
<mkdir dir="${j4k.bin}" />
<mkdir dir="${j4k.dist}" />
<!--copy todir="${j4k.bin}">
<fileset dir="${j4k.src}">
<include name="*.png"/>
</fileset>
</copy-->
</target>

<target name="compile" depends="init" description="compiles all source files">
<!-- Compile the java code from ${j4k.src} into ${bin} -->
<javac destdir="${j4k.bin}" debug="off" deprecation="off">
<src path="${j4k.src}" />
<include name="**/*.java" />
</javac>
</target>

<target name="recompile" depends="clean, compile" description="rebuilds the project" />

<target name="_package_jar" depends="compile" description="generate the jar file">
<zip destfile="${j4k.dist}/Asteroids4Kpre.jar" compress="yes">
<fileset dir="${j4k.bin}">
<include name="*.class" />
</fileset>
</zip>
</target>

<!--target name="_obfuscate_1" depends="_package_jar" description="obfuscate/compress classes">
<proguard verbose="true">
-keep public class A {
public static void main(java.lang.String[]);
}
<injar path="${j4k.dist}/Asteroids4Kpre.jar" />
<outjar path="${j4k.dist}/Asteroids4Kpre1.jar" />
<libraryjar path="C:/Apps/Programming/Java/j2sdk1.4.2_10/jre/lib/rt.jar" />
</proguard>
</target>

<target name="_unzip_1" depends="_obfuscate_1" description="obfuscate/compress classes">
<unzip src="${j4k.dist}/Asteroids4Kpre1.jar" dest="${j4k.dist}" />
</target>

<target name="_rezip_1" depends="_unzip_1" description="generate the jar file">
<zip destfile="${j4k.dist}/Asteroids4Kpre2.jar" compress="yes">
<fileset dir="${j4k.dist}">
<include name="*.class" />
</fileset>
</zip>
</target>

<target name="_obfuscate_2" depends="_rezip_1" description="obfuscate/compress classes">
<jarg jarfile="${j4k.dist}/Asteroids4Kpre.jar" verbose="true" rnlog="rnlog.txt" />
</target-->

<target name="_unzip_2" depends="_package_jar" description="obfuscate/compress classes">
<unzip src="${j4k.dist}/Asteroids4Kpre.jar" dest="${j4k.dist}" />
</target>

<target name="_rezip_2" depends="_unzip_2" description="obfuscate/compress classes" >
<exec executable="7z" output="error.log" dir="${j4k.dist}">
<arg value="a" />
<arg value="-tzip" />
<arg value="Asteroids4K.zip" />
<arg value="A.class" />
<arg value="-mx9" />
<arg value="-mpass=9" />
</exec>
</target>

<target name="_rezip_3" depends="_unzip_2" description="obfuscate/compress classes" >
<exec executable="bjwflate" output="error.log" dir="${j4k.dist}">
<arg value="-n" />
<arg value="Asteroids4K.zip" />
<arg value="A.class" />
</exec>
</target>

<target name="_rename" depends="_rezip_2" description="rename zip to jar">
<move file="${j4k.dist}/Asteroids4K.zip" tofile="${j4k.dist}/Asteroids4K.jar" />
</target>

<target name="build" depends="_rename" description="deletes classes and archive directories">
</target>

<target name="rebuild" depends="clean, build" description="rebuilds the project" />

<target name="deploy" depends="build" description="capy jar to web folder" >
<copy file="${j4k.dist}/Asteroids4K.jar" todir="C:/Documents and Settings/Mark/My Documents/htdocs">
</copy>
</target>

<target name="redeploy" depends="clean, deploy" description="redeploy the project" />

<target name="_re_package_jar" depends="clean, _package_jar" description="generate the jar file">
<zip destfile="${j4k.dist}/Asteroids4Kpre.jar">
<fileset dir="${j4k.bin}">
<include name="*.class" />
<!--include name="*.png" /-->
</fileset>
</zip>
</target>
</project>

Share this post


Link to post
Share on other sites

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this