You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 $?;
The text was updated successfully, but these errors were encountered:
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;
^
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.
The text was updated successfully, but these errors were encountered: