Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class can not find other classes (source path is not set) #4

Open
macfreek opened this issue Aug 21, 2010 · 2 comments
Open

class can not find other classes (source path is not set) #4

macfreek opened this issue Aug 21, 2010 · 2 comments

Comments

@macfreek
Copy link

Here is a patch that will set the source path to the directory of the source file during compiling. This allows a class to find other classes in the same directory. Currently, I'm getting errors that the class is not found.

The given fix also sets the folder to the root of the package directory, so it works fine with packages too. As an added fix, it prints the javac line, so it is clear what is going on.

diff --git a/Support/bin/java_compile_and_run.sh b/Support/bin/java_compile_and_run.sh
index 4e32e6c..26e9b75 100755
--- a/Support/bin/java_compile_and_run.sh
+++ b/Support/bin/java_compile_and_run.sh
@@ -12,13 +12,19 @@ shift
 output="$TMPDIR/tm_javamate.${TM_PID:-$LOGNAME}";
 mkdir -p "$output"

+PACKAGEDIR=${TM_JAVA_PACKAGE//./\/}    # replace . with / in package
+SOURCEDIR=$(dirname "$SOURCE")
+SOURCEDIR=${SOURCEDIR/%\/$PACKAGEDIR/} # remove package prefix from path
+
 if [ -n "$TM_JAVA_FILEGLOB" ]; then
-  "$TM_JAVAC" -d "$output" $TM_JAVA_FILEGLOB; rc=$?;
+  echo "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" $TM_JAVA_FILEGLOB;
+  "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" $TM_JAVA_FILEGLOB; rc=$?;
   if (($rc >= 1)); then exit $rc; fi
 fi

 if [[ "$SOURCE" != $TM_JAVA_FILEGLOB ]]; then
-  "$TM_JAVAC" -d "$output" "$SOURCE"; rc=$?;
+  echo "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" $SOURCE;
+  "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" "$SOURCE"; rc=$?;
   if (($rc >= 1)); then exit $rc; fi
 fi

@@ -28,6 +34,6 @@ then
    CLASS="$TM_JAVA_PACKAGE.$CLASS"
 fi

-echo CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding=utf-8 "$CLASS" $@;
-CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding=utf-8 "$CLASS" $@;
+echo CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding="utf-8" "$CLASS" $@;
+CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding="utf-8" "$CLASS" $@;
 exit $?;
@macfreek
Copy link
Author

Oh, and I put quotes around utf-8; somehow, I got a message "don't know what the -8 flags means". I didn't examine the cause; the quotes fixed it.

@macfreek
Copy link
Author

I hope my description is clear. Currently, if I try to use a class in the same folder or import a class in the same package, I get errors because the referred class can not be found. Like this:

/Users/freek/Code/Java/OSXAdapter/src/org/example/myapp/MyApp.java:17: cannot find symbol
symbol  : class OSXAdapter
location: package org.example.myapp
import org.example.myapp.OSXAdapter;
                         ^

this patch makes sure these classes can be found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant